Skip to content

Commit

Permalink
Harden _Q.push wrapper in the amzn_apstag.js shim
Browse files Browse the repository at this point in the history
Apstag calls are queued onto the `window.apstag._Q` array and are then
called when the Apstag script is ready. Each queued call is usually an
array containing the API method name prefix and arguments, e.g.

    ["f", {slots: [...], timeout: 3000}, () => { ... }]

Some websites however seem to queue up the calls differently, with a
queued call looking something like this instead:

    [["f", Arguments([{slots: [...], timeout: 3000}, () => { ... }])]]

Since the original script handles that, the shim needs to as
well. Let's try our best here.
  • Loading branch information
kzar committed Mar 18, 2024
1 parent 57b338a commit 5b5398a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions surrogates/amzn_apstag.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ if (!(window.apstag && window.apstag._getSlotIdToNameMapping)) {
window.apstagLOADED = true;

_Q.push = function(prefix, args) {
if (Array.isArray(prefix) && typeof args === "undefined") {
[prefix, ...args] = prefix;
}
if (args.length === 1 &&
(args[0].toString() === "[object Arguments]" || Array.isArray(args[0]))) {
args = Array.from(args[0]);
}

try {
switch (prefix) {
case "f":
Expand Down

0 comments on commit 5b5398a

Please sign in to comment.