Skip to content

Commit e24751e

Browse files
committed
Merge branch 'release/v0.2.1'
2 parents 568c31d + 43fa6c3 commit e24751e

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@adnbn/inject-script",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "A lightweight, TypeScript-ready library for injecting JavaScript functions or external scripts into Chrome extension tabs and frames (Manifest V2 & V3).",
55
"keywords": [
66
"browser",
@@ -41,7 +41,7 @@
4141
"build:watch": "tsup --watch"
4242
},
4343
"dependencies": {
44-
"@adnbn/browser": "^0.1.5",
44+
"@adnbn/browser": "^0.1.7",
4545
"nanoid": "^5.1.5"
4646
},
4747
"devDependencies": {

src/InjectScriptV2.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ export default class extends AbstractInjectScript {
3232
if (message?.type !== type) return;
3333

3434
const {result, error} = message?.data;
35-
const {frameId, documentId} = sender;
35+
const {frameId, documentId = ""} = sender;
3636

3737
frameCount -= 1;
3838

39-
if (frameId == null || documentId == null) {
39+
if (frameId == null) {
4040
throw new Error("frameId or documentId is missing in sender");
4141
}
4242

src/InjectScriptV3.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {executeScript} from "@adnbn/browser";
1+
import {executeScript, getBrowserInfo} from "@adnbn/browser";
22

33
import AbstractInjectScript from "./AbstractInjectScript";
44

@@ -18,7 +18,7 @@ export default class extends AbstractInjectScript {
1818
args?: A
1919
): Promise<InjectionResult<Awaited<R>>[]> {
2020
return executeScript({
21-
target: this.target,
21+
target: await this.target(),
2222
world: this._options.world,
2323
injectImmediately: this.injectImmediately,
2424
func,
@@ -28,20 +28,30 @@ export default class extends AbstractInjectScript {
2828

2929
public async file(fileList: string | string[]): Promise<void> {
3030
await executeScript({
31-
target: this.target,
31+
target: await this.target(),
3232
world: this._options.world,
3333
injectImmediately: this.injectImmediately,
3434
files: typeof fileList === "string" ? [fileList] : fileList,
3535
});
3636
}
3737

38-
protected get target(): InjectionTarget {
39-
return {
38+
protected async target(): Promise<InjectionTarget> {
39+
const target = {
4040
tabId: this._options.tabId,
4141
allFrames: this.allFrames,
4242
frameIds: this.frameIds,
43-
documentIds: this.documentIds,
4443
};
44+
45+
try {
46+
const {name} = await getBrowserInfo();
47+
48+
// Firefox does not support `documentIds` in the target
49+
if (name === "Firefox") {
50+
return target;
51+
}
52+
} catch (err) {}
53+
54+
return {...target, documentIds: this.documentIds};
4555
}
4656

4757
protected get documentIds(): string[] | undefined {

0 commit comments

Comments
 (0)