Skip to content

Commit 8f8afa6

Browse files
committed
localstripe.js: Fix LOCALSTRIPE_BASE_API on dynamical load
This continues commit c89bb15 "API: Allow serving localstripe API from a custom URL" by simplifying the way to get localstripe server URL, and also fixes the case when `localstripe.js` is loaded dynamically (in this case, `document.getElementsByTagName('script')` references the wrong element: the calling/parent `<script>`) like this: let script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'http://localhost:8420/js.stripe.com/v3/'; document.head.appendChild(script);
1 parent 39c1ebb commit 8f8afa6

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

localstripe/localstripe-v3.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717

1818
// First, get the URL base from which this script is pulled:
1919
const LOCALSTRIPE_BASE_API = (function () {
20-
const scripts = document.getElementsByTagName('script');
21-
const src = scripts[scripts.length - 1].src;
20+
const src = document.currentScript.src;
2221
if (src.match(/\/js\.stripe\.com\/v3\/$/)) {
2322
return src.replace(/\/js\.stripe\.com\/v3\/$/, '');
2423
} else {

0 commit comments

Comments
 (0)