PageSourceSearch

https://littlebirdelectronics.com.au/assets/controllers/ecommerce/paypal_loader-6ee75676.js

js littlebirdelectronics.com.au collected 2026-09-25 14:10:59 UTC 1,965 bytes, 39 lines download raw bytes

1// Robustly loading the PayPal JS SDK on the checkout page — the PayPal clone
2// of stripe_loader.js. The SDK arrives via a plain `<script async>` tag in the
3// checkout layout; ad/privacy blockers, DNS blocklists and corporate firewalls
4// can stop that request, in which case the global `paypal` object never
5// appears. Bound wait + onerror flag so a blocked script surfaces a real
6// message instead of a PayPal button that never draws.
7
8const PAYPAL_POLL_INTERVAL_MS = 100
9
10// Budgeted in poll ticks rather than wall-clock time for the same reason as
11// stripe_loader: browsers throttle timers in backgrounded tabs, so a wall
12// clock would "burn" while the tab is frozen and wrongly declare a
13// still-loading SDK blocked the instant it resumes.
14const PAYPAL_LOAD_TIMEOUT_TICKS = 100
15
16export const PAYPAL_BLOCKED_MESSAGE =
17  "We couldn't load PayPal. This is usually caused by an ad blocker, privacy extension, or network issue — please disable any blocker and reload the page, or pay by card instead."
18
19// Resolves once the global `paypal` SDK object is available; rejects if the
20// script fails to load. The layout's `<script onerror>` sets
21// `window.paypalJsBlocked` so an ERR_BLOCKED_BY_CLIENT rejects immediately;
22// the tick budget backstops every other failure.
23export function waitForPaypal({ maxTicks = PAYPAL_LOAD_TIMEOUT_TICKS } = {}) {
24  return new Promise((resolve, reject) => {
25    if (typeof window.paypal !== "undefined" && window.paypal.Buttons) { resolve(); return }
26    if (window.paypalJsBlocked) { reject(new Error("PayPal SDK blocked")); return }
27
28    let ticks = 0
29    const interval = setInterval(() => {
30      if (typeof window.paypal !== "undefined" && window.paypal.Buttons) {
31        clearInterval(interval)
32        resolve()
33      } else if (window.paypalJsBlocked || ++ticks >= maxTicks) {
34        clearInterval(interval)
35        reject(new Error("PayPal SDK failed to load"))
36      }
37    }, PAYPAL_POLL_INTERVAL_MS)
38  })
39}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.