Skip to content

Fix: detect script injection API before calling it (CPH Submit error) - #38

Merged
agrawal-d merged 2 commits into
agrawal-d:masterfrom
sathwikhbhat:fix-executescript-error
Apr 30, 2026
Merged

Fix: detect script injection API before calling it (CPH Submit error)#38
agrawal-d merged 2 commits into
agrawal-d:masterfrom
sathwikhbhat:fix-executescript-error

Conversation

@sathwikhbhat

Copy link
Copy Markdown
Contributor

Description

Fixes a runtime error when submitting with CPH Submit:
TypeError: browser.tabs.executeScript is not a function
The submission page opened, but script injection failed, so the submission didn’t complete.

Root Cause

browser.tabs.executeScript isn’t available in all environments (e.g., Manifest V3), causing a runtime error.

Fix

  • Use chrome.scripting.executeScript when available
  • Fall back to browser.tabs.executeScript otherwise

Changes

  • Added API detection before script injection
  • Updated handleSubmit.ts

Testing

  • Tested locally in Chrome (Manifest V3) Version 147.0.7727.116 (Official Build) (64-bit)
  • No console errors, submission works

Closes #37

Copilot AI review requested due to automatic review settings April 27, 2026 02:57
@sathwikhbhat
sathwikhbhat deleted the fix-executescript-error branch April 27, 2026 02:59
@sathwikhbhat
sathwikhbhat restored the fix-executescript-error branch April 27, 2026 02:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR prevents a runtime failure during submission by guarding against environments where browser.tabs.executeScript is present as an object but not available as a callable function (e.g., Manifest V3), ensuring the code falls back to chrome.scripting.executeScript instead.

Changes:

  • Added a function-availability check for browser.tabs.executeScript before attempting MV2-style script injection.
  • Ensures MV3 injection via chrome.scripting.executeScript is used when browser.tabs.executeScript is unavailable.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sathwikhbhat sathwikhbhat reopened this Apr 27, 2026
@agrawal-d

Copy link
Copy Markdown
Owner

Thanks!

@agrawal-d
agrawal-d merged commit b4d4e1b into agrawal-d:master Apr 30, 2026
2 checks passed
@sathwikhbhat
sathwikhbhat deleted the fix-executescript-error branch April 30, 2026 15:02
@sathwikhbhat

Copy link
Copy Markdown
Contributor Author

Thanks for merging my PR, @agrawal-d. Missed formatting the code, my bad...

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.

Submission page opens but fails with browser.tabs.executeScript is not a function error

3 participants