4
12
Fork
You've already forked userscripts
2

Update simple-sponsor-skipper/simple-sponsor-skipper.user.js - 'document.body is null' error on Pale Moon #23

Open
sinfulosd wants to merge 1 commit from sinfulosd/userscripts:master into master
pull from: sinfulosd/userscripts:master
merge into: mthsk:master
mthsk:master
First-time contributor
Copy link

Simple Sponsor Skipper document.body is null error on Pale Moon

Line 137 of the script sets up a setInterval to look for a video element, and the callback body on line 139 is:

const plr = document.body.querySelector(PLR_SELECTOR);

The race is in the script: it schedules setInterval(..., ~250ms?) at document-start, and if the first tick lands before the parser inserts <body>, document.body is still null and .querySelector throws. On a slow connection or a heavy page like YouTube, that race window is wide.

You explicitly avoided optional chaining (?.) for Pale Moon compatibility, but then forgot to guard document.body the same way one line down.

2 things can happen, either:

  1. change line 139 to const plr = document.body && document.body.querySelector(PLR_SELECTOR);
  2. Or change // @run-at document-start to // @run-at document-end. the script only needs to find a <video> element, which doesn't exist until DOM-end anyway, so document-start gains nothing here.

I decided to just make a PR to the first one, but it's completely up to you, at the end of the day - I just decided to make a PR since a lot of Pale Moon users are using this userscript on my userscript manager of Greasemonkey for UXP (Including me, but I wouldn't just be content with making the changes locally, I thought it would be worth giving you a nudge about your userscript)

Simple Sponsor Skipper `document.body is null` error on Pale Moon Line 137 of the script sets up a setInterval to look for a video element, and the callback body on line 139 is: `const plr = document.body.querySelector(PLR_SELECTOR);` The race is in the script: it schedules `setInterval(..., ~250ms?)` at document-start, and if the first tick lands before the parser inserts `<body>`, `document.body` is still null and `.querySelector` throws. On a slow connection or a heavy page like YouTube, that race window is wide. You explicitly avoided optional chaining (`?.`) for Pale Moon compatibility, but then forgot to guard `document.body` the same way one line down. 2 things can happen, either: 1. change line 139 to `const plr = document.body && document.body.querySelector(PLR_SELECTOR);` 2. Or change `// @run-at document-start` to `// @run-at document-end`. the script only needs to find a `<video>` element, which doesn't exist until DOM-end anyway, so document-start gains nothing here. I decided to just make a PR to the first one, but it's completely up to you, at the end of the day - I just decided to make a PR since a lot of Pale Moon users are using this userscript on my userscript manager of Greasemonkey for UXP (Including me, but I wouldn't just be content with making the changes locally, I thought it would be worth giving you a nudge about your userscript)
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u master:sinfulosd-master
git switch sinfulosd-master

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch master
git merge --no-ff sinfulosd-master
git switch sinfulosd-master
git rebase master
git switch master
git merge --ff-only sinfulosd-master
git switch sinfulosd-master
git rebase master
git switch master
git merge --no-ff sinfulosd-master
git switch master
git merge --squash sinfulosd-master
git switch master
git merge --ff-only sinfulosd-master
git switch master
git merge sinfulosd-master
git push origin master
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mthsk/userscripts!23
Reference in a new issue
mthsk/userscripts
No description provided.
Delete branch "sinfulosd/userscripts:master"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?