feat: add Safari Web Extension support#337
Open
coryboyle wants to merge 2 commits intoBabylonJS:masterfrom
Open
feat: add Safari Web Extension support#337coryboyle wants to merge 2 commits intoBabylonJS:masterfrom
coryboyle wants to merge 2 commits intoBabylonJS:masterfrom
Conversation
Add a Safari Web Extension in safari-extension/ that ports Spector.js debugging capabilities to Safari on macOS. Key implementation details: - Uses browser.scripting.registerContentScripts() with world: MAIN for CSP-safe getContext() interception (Safari doesn't support manifest-declared MAIN world content scripts) - Injects Spector bundle via scripting.executeScript() to bypass page Content Security Policy restrictions - Single ISOLATED-world content script bridges extension APIs and page CustomEvents - getContext patch uses Function.prototype.apply() with try-catch to ensure extension errors never break page WebGL functionality Also includes: - Build script updates (copies bundle to safari-extension/) - GitHub Actions CI job on macOS runner - Safari extension documentation - Copilot instructions for the repository Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
sebavan
requested changes
Mar 17, 2026
Member
sebavan
left a comment
There was a problem hiding this comment.
it looks like a lot of code in the safari-extension folder is a dupplicate and this might make maintenance harder.
Any way to share any shareable thing ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add Safari Web Extension support for macOS, enabling Spector.js WebGL debugging in Safari.
Architecture
The Safari extension lives in
safari-extension/(separate from the Chrome/Firefoxextensions/directory) because Safari requires a fundamentally different approach to MAIN-world code execution.Key design decisions
browser.scripting.registerContentScripts()withworld: "MAIN"— Safari doesn't support manifest-declared MAIN-world content scripts. The scripting API registerspageScript.jsas a MAIN-world content script at runtime, which bypasses page CSP and runs atdocument_start.browser.scripting.executeScript()— Injects the Spector bundle and initialization code into the page's MAIN world on demand (when the user enables Spector), also bypassing CSP.contentScript.jshandles allbrowser.runtimemessaging and bridges to the MAIN world via CustomEvents and shared DOM elements.Function.prototype.apply()for argument forwarding and wraps all extension logic in try-catch to ensure extension errors never break page WebGL functionality.Files
safari-extension/manifest.jsonscriptingpermissionsafari-extension/pageScript.jssafari-extension/pageScriptInit.jssafari-extension/contentScript.jssafari-extension/background.jssafari-extension/popup.html/jssafari-extension/result.html/jsdocumentation/safari-extension.mdBuild & Test
Then open the Xcode project, build & run, and enable the extension in Safari.
Also included