Skip to content

Conversation

@mxmou
Copy link
Member

@mxmou mxmou commented Nov 19, 2025

Resolves #8682

Changes

Changes the way background and settings page code detects that it's running on Firefox: instead of checking if window.browser exists, it now checks if a Firefox-specific API is available. I've made a shared module to detect the browser so that it's easy to update in the future if needed.

Reason for changes

The window.browser namespace will soon exist in both Chromium and Firefox.

Tests

Tested on Edge v144 (dev channel) and Firefox.

@mxmou mxmou self-assigned this Nov 19, 2025
@mxmou mxmou added platform: chrome Related to Chrome / ChromeOS scope: upstream Related to something we depend on (like Scratch, a library, or the browser) labels Nov 19, 2025
@yuri-kiss
Copy link
Contributor

what if chrome goes and adds this api too though, also maybe try more strict checking?

stuff like Error().fileName != (void 0) has worked for a long time to detect firefox.

@mxmou
Copy link
Member Author

mxmou commented Nov 20, 2025

My first idea was to call the getBrowserInfo() function if it exists and check the result. Unfortunately, it's async, so that would require additional changes in each place that needs to check the browser.

stuff like Error().fileName != (void 0) has worked for a long time to detect firefox.

That's probably better. We could also just check the userAgent - some addons already do that.

@yuri-kiss
Copy link
Contributor

yuri-kiss commented Nov 20, 2025

My first idea was to call the getBrowserInfo() function if it exists and check the result. Unfortunately, it's async, so that would require additional changes in each place that needs to check the browser.

stuff like Error().fileName != (void 0) has worked for a long time to detect firefox.

That's probably better. We could also just check the userAgent - some addons already do that.

yeah that is what I do when I am to bored to get feature based detection, I do the error thing and the userAgent. (though the user agent lies sometimes)

@mxmou
Copy link
Member Author

mxmou commented Nov 28, 2025

I've changed the detection code so that it works outside the extension context. I used Error.fileName as suggested by @yuri-kiss, but that can be easily changed if needed.

@DNin01 DNin01 added this to the v1.45.0 milestone Dec 3, 2025
Copy link
Contributor

@yuri-kiss yuri-kiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ik my review means nothing but, this works on older chromium versions and firefox too.

@mxmou mxmou merged commit 60da0a6 into ScratchAddons:master Dec 4, 2025
2 checks passed
@mxmou mxmou deleted the typeof-browser branch December 4, 2025 13:13
WorldLanguages pushed a commit that referenced this pull request Dec 12, 2025
The window.browser namespace will soon exist in both Chromium and Firefox.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform: chrome Related to Chrome / ChromeOS scope: upstream Related to something we depend on (like Scratch, a library, or the browser)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chromium will soon support window.browser

4 participants