Skip to content

Commit

Permalink
feat(background): Improve compatibility for Safari
Browse files Browse the repository at this point in the history
- Detect Safari browser explicitly
- Adjust execution world to 'MAIN' for Safari, 'chrome.scripting.ExecutionWorld.MAIN' for other browsers
  • Loading branch information
ERosendo committed Oct 31, 2024
1 parent f743455 commit 0618658
Showing 1 changed file with 8 additions and 4 deletions.
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: chrome.scripting.ExecutionWorld.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: chrome.scripting.ExecutionWorld.MAIN,
world: executionWorld,
})
.then((injectionResults) => sendResponse(injectionResults));
}

0 comments on commit 0618658

Please sign in to comment.