Skip to content

Commit d9a3eb7

Browse files
committed
fix: correct broken sandbox lookup
1 parent fd88aa5 commit d9a3eb7

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/bidiMapper/modules/cdp/CdpTargetManager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ export class CdpTargetManager {
263263
case 'worker': {
264264
const realm = this.#realmStorage.findRealm({
265265
cdpSessionId: parentSessionCdpClient.sessionId,
266+
sandbox: null, // Non-sandboxed realms.
266267
});
267268
// If there is no browsing context, this worker is already terminated.
268269
if (!realm) {

src/bidiMapper/modules/script/RealmStorage.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ interface RealmFilter {
3131
executionContextId?: Protocol.Runtime.ExecutionContextId;
3232
origin?: string;
3333
type?: Script.RealmType;
34-
sandbox?: string;
34+
// null indicates no sandbox.
35+
sandbox?: string | null;
3536
cdpSessionId?: Protocol.Target.SessionID;
3637
isHidden?: boolean;
3738
}
@@ -59,6 +60,8 @@ export class RealmStorage {
5960

6061
/** Finds all realms that match the given filter. */
6162
findRealms(filter: RealmFilter): Realm[] {
63+
const sandboxFilterValue =
64+
filter.sandbox === null ? undefined : filter.sandbox;
6265
return Array.from(this.#realmMap.values()).filter((realm) => {
6366
if (filter.realmId !== undefined && filter.realmId !== realm.realmId) {
6467
return false;
@@ -73,7 +76,8 @@ export class RealmStorage {
7376
}
7477
if (
7578
filter.sandbox !== undefined &&
76-
(!(realm instanceof WindowRealm) || filter.sandbox !== realm.sandbox)
79+
(!(realm instanceof WindowRealm) ||
80+
sandboxFilterValue !== realm.sandbox)
7781
) {
7882
return false;
7983
}
@@ -106,11 +110,7 @@ export class RealmStorage {
106110
}
107111

108112
findRealm(filter: RealmFilter): Realm | undefined {
109-
const maybeRealms = this.findRealms(filter);
110-
if (maybeRealms.length !== 1) {
111-
return undefined;
112-
}
113-
return maybeRealms[0];
113+
return this.findRealms(filter)[0];
114114
}
115115

116116
/** Gets the only realm that matches the given filter, if any, otherwise throws. */

0 commit comments

Comments
 (0)