Skip to content

fix(safari): prevent context loss by calling scripting methods natively - #79

Closed
StifflyAnyhow wants to merge 1 commit into
fregante:mainfrom
StifflyAnyhow:fix/safari-scripting-bind
Closed

fix(safari): prevent context loss by calling scripting methods natively#79
StifflyAnyhow wants to merge 1 commit into
fregante:mainfrom
StifflyAnyhow:fix/safari-scripting-bind

Conversation

@StifflyAnyhow

@StifflyAnyhow StifflyAnyhow commented May 12, 2026

Copy link
Copy Markdown

Uses globalThis.chrome.scripting.registerContentScripts and globalThis.browser.contentScripts.register directly instead of cached references to prevent this context loss in Safari.

Unblocks refined-github/refined-github#9441 by re-enabling dynamic content script registration on Safari, which was previously broken because the cached chrome.scripting reference lost its this binding.

Safari requires `this` to be bound when calling `chrome.scripting` methods. Storing `registerContentScripts` as a bare reference loses the `this` context, causing it to fail on Safari. Instead of tearing off the methods, we now use booleans for feature detection and call the methods directly on their parent objects to naturally preserve the context.
@StifflyAnyhow
StifflyAnyhow force-pushed the fix/safari-scripting-bind branch from 38f126c to 038221a Compare May 12, 2026 05:31
@fregante

Copy link
Copy Markdown
Owner

Closing because #76 will eventually do the same

@fregante fregante closed this May 12, 2026
@fregante fregante mentioned this pull request Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants