Skip to content

Fix Chrome script injection API detection#1

Open
fkuefler wants to merge 1 commit intoadervark:fix/service-worker-lifecyclefrom
fkuefler:fix/chrome-api-detection
Open

Fix Chrome script injection API detection#1
fkuefler wants to merge 1 commit intoadervark:fix/service-worker-lifecyclefrom
fkuefler:fix/chrome-api-detection

Conversation

@fkuefler
Copy link
Copy Markdown

@fkuefler fkuefler commented Apr 3, 2026

Summary

This fixes a Chrome runtime failure when submitting through the extension.

Chrome can expose a browser namespace, so checking only typeof browser !== 'undefined' is not a reliable Firefox check. In Chrome, that caused the extension to call browser.tabs.executeScript, which is not available there under Manifest V3, leading to:

TypeError: browser.tabs.executeScript is not a function

What changed

  • Use browser.tabs.executeScript only when that specific function exists
  • Otherwise fall back to chrome.scripting.executeScript, which is the correct Chrome Manifest V3 path
  • Remove the self.chrome = browser shim from the affected files

Files changed

  • src/handleSubmit.ts
  • src/injectedScript.ts

Verification

  • Built the extension with npm run webpack
  • Regenerated the unpacked Chrome build with ./create-zip.sh
  • Loaded the unpacked extension in Chrome
  • Confirmed the previous browser.tabs.executeScript error no longer occurred

@fkuefler
Copy link
Copy Markdown
Author

fkuefler commented Apr 3, 2026

Really appreciate your fix. Not sure if the original repo owner is ever going to merge your PR, but if he does this fixes a small issue I was having.

@ayaantuts
Copy link
Copy Markdown

Hello @fkuefler
Really appreciate your fix! It works.
I would like to suggest one small change that I noticed:

  • CodeForces uses anti-bot verification powered by CloudFlare.
  • It takes much longer to verify. Till then, the extension tries to submit the code, leading to the error: Please complete the anti-bot verification.
  • It would be great to implement a timeout function or a listener to wait for completion of anti-bot verification?

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