Skip to content

Commit

Permalink
Merge pull request #404 from ttys0dev/fix-firefox-world
Browse files Browse the repository at this point in the history
fix(background): use chrome.scripting.ExecutionWorld.MAIN for firefox compatibility
  • Loading branch information
ERosendo authored Oct 31, 2024
2 parents 95084d5 + 0618658 commit 7d87622
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [14.x, 16.x, 18.x]
steps:
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Fixes:
- Improves the reliability of PACER case ID retrieval on attachment pages ([369](https://github.com/freelawproject/recap/issues/369), [400](https://github.com/freelawproject/recap-chrome/pull/400)).
- Fix setDefaultOptions in updateToolbarButton([403](https://github.com/freelawproject/recap-chrome/pull/403))
- Ensure we call sendResponse even when notifications are disabled([405](https://github.com/freelawproject/recap-chrome/pull/405))
- Use chrome.scripting.ExecutionWorld.MAIN for firefox compatibility ([404](https://github.com/freelawproject/recap-chrome/pull/404))


For developers:
Expand Down
12 changes: 8 additions & 4 deletions src/utils/background.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { getCourtFromUrl } from './url_and_cookie_helpers.js';

let isSafari =
/Safari/.test(navigator.userAgent) &&
!/Chrome|Chromium/.test(navigator.userAgent);
let executionWorld = isSafari ? 'MAIN' : chrome.scripting.ExecutionWorld.MAIN;

export function chooseVariant(details) {
const options = ['A-A', 'A-C', 'B-B', 'B-D'];
const randomIndex = Math.floor(Math.random() * options.length);
Expand Down Expand Up @@ -123,13 +128,12 @@ export function getAndStoreVueData(req, sender, sendResponse) {
.executeScript({
target: { tabId: sender.tab.id },
func: getVueDiv,
world: 'MAIN',
world: executionWorld,
})
.then((injectionResults) => sendResponse(injectionResults));
}


export function overwriteSubmitMethod(req, sender, sendResponse){
export function overwriteSubmitMethod(req, sender, sendResponse) {
const _overwriteScript = () => {
document.createElement('form').__proto__.submit = function () {
this.id = 'form' + new Date().getTime();
Expand All @@ -154,7 +158,7 @@ export function overwriteSubmitMethod(req, sender, sendResponse){
.executeScript({
target: { tabId: sender.tab.id },
func: _overwriteScript,
world: 'MAIN',
world: executionWorld,
})
.then((injectionResults) => sendResponse(injectionResults));
}

0 comments on commit 7d87622

Please sign in to comment.