Skip to content

Commit fe95569

Browse files
authored
Merge pull request #388 from ulixee/worklet
fix(puppet): don't use contexts we didn't initiate
2 parents aad189b + 710acab commit fe95569

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

plugins/default-browser-emulator/lib/DomOverridesBuilder.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ export default class DomOverridesBuilder {
2525
{
2626
// NOTE: don't make this async. It can cause issues if you read a frame right after creation, for instance
2727
script: `(function newDocumentScript() {
28+
// Worklet has no scope to override, but we can't detect until it loads
29+
if (typeof self === 'undefined' && typeof window === 'undefined') return;
30+
2831
const sourceUrl = '${injectedSourceUrl}';
32+
2933
${utilsScript}
3034
3135
${scripts.join('\n\n')}

puppet-chrome/lib/FramesManager.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ export default class FramesManager extends TypedEventEmitter<IPuppetFrameManager
198198
await this.isReady;
199199
const { context } = event;
200200
const frameId = context.auxData.frameId as string;
201+
const type = context.auxData.type as string;
202+
203+
const defaultScope =
204+
type === 'default' && context.auxData.isDefault === true && context.name === '';
205+
const isolatedScope = type === 'isolated' && context.name === ISOLATED_WORLD;
206+
if (!isolatedScope && !defaultScope) return;
201207

202208
this.activeContextIds.add(context.id);
203209
const frame = this.framesById.get(frameId);
@@ -207,7 +213,7 @@ export default class FramesManager extends TypedEventEmitter<IPuppetFrameManager
207213
executionContextId: context.id,
208214
});
209215
}
210-
frame?.addContextId(context.id, context.name === '' || context.auxData?.isDefault === true);
216+
frame?.addContextId(context.id, defaultScope);
211217
}
212218

213219
/////// FRAMES ///////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)