Skip to content

Commit 16b5880

Browse files
talkensonshadowusr
authored andcommitted
feat: add custom firefox extension to bypass csp
1 parent 04338c7 commit 16b5880

File tree

6 files changed

+18
-1
lines changed

6 files changed

+18
-1
lines changed

assets/[email protected]

8.89 KB
Binary file not shown.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"scripts": {
2121
"build": "tsc --build && npm run build-bundles && npm run copy-static && node scripts/create-client-scripts-symlinks.js",
22-
"copy-static": "copyfiles 'src/browser/client-scripts/*' 'src/**/[!cache]*/autogenerated/**/*.json' build",
22+
"copy-static": "copyfiles 'src/browser/client-scripts/*' 'src/**/[!cache]*/autogenerated/**/*.json' 'assets/*' build",
2323
"build-node-bundle": "esbuild ./src/bundle/cjs/index.ts --outdir=./build/src/bundle/cjs --bundle --format=cjs --platform=node --target=ES2021",
2424
"build-browser-bundle": "node ./src/browser/client-scripts/build.js",
2525
"build-bundles": "concurrently -c 'auto' 'npm:build-browser-bundle' 'npm:build-node-bundle --minify'",

src/browser/browser.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { BrowserConfig } from "../config/browser-config";
1414
import type { Callstack } from "./history/callstack";
1515
import type { WdProcess, WebdriverPool } from "../browser-pool/webdriver-pool";
1616
import { configure, setupBrowser } from "./queries";
17+
import { getFirefoxCSPAddOn } from "./queries/firefoxCSPAddOn";
18+
import { getNormalizedBrowserName } from "../utils/browser";
1719

1820
const CUSTOM_SESSION_OPTS = [
1921
"outputDir",
@@ -103,6 +105,12 @@ export class Browser {
103105
this._addExtendOptionsMethod(this._session!);
104106
}
105107

108+
protected async _installFirefoxCSPAddOn(): Promise<string> {
109+
if (getNormalizedBrowserName(this._session!.capabilities.browserName) !== "firefox") return Promise.resolve("");
110+
const firefoxCSPAddOn = await getFirefoxCSPAddOn();
111+
return this._session!.installAddOn(firefoxCSPAddOn, false);
112+
}
113+
106114
protected _addQueries(): void {
107115
configure({ testIdAttribute: this._config.testIdAttribute, asyncUtilTimeout: this._config.waitTimeout });
108116
setupBrowser(this._session!);

src/browser/existing-browser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export class ExistingBrowser extends Browser {
8484

8585
this._extendStacktrace();
8686
this._addSteps();
87+
await this._installFirefoxCSPAddOn();
8788
this._addQueries();
8889
this._addHistory();
8990

src/browser/new-browser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export class NewBrowser extends Browser {
7373

7474
this._extendStacktrace();
7575
this._addSteps();
76+
await this._installFirefoxCSPAddOn();
7677
this._addQueries();
7778
this._addHistory();
7879

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import fs from "fs/promises";
2+
import path from "path";
3+
4+
export const getFirefoxCSPAddOn = async (): Promise<string> => {
5+
const extension = await fs.readFile(path.join(__dirname, "../../../assets/[email protected]"));
6+
return extension.toString("base64");
7+
};

0 commit comments

Comments
 (0)