Skip to content

Commit

Permalink
chore: addScriptToEvaluateOnNewDocument on page
Browse files Browse the repository at this point in the history
  • Loading branch information
jrandolf committed Aug 23, 2022
1 parent 341b669 commit c4d9525
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
9 changes: 2 additions & 7 deletions src/common/FrameManager.ts
Expand Up @@ -23,7 +23,7 @@ import {
import {isErrorLike} from '../util/ErrorLike.js';
import {CDPSession} from './Connection.js';
import {EventEmitter} from './EventEmitter.js';
import {EVALUATION_SCRIPT_URL, ExecutionContext} from './ExecutionContext.js';
import {ExecutionContext} from './ExecutionContext.js';
import {Frame} from './Frame.js';
import {IsolatedWorld, MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorld.js';
import {NetworkManager} from './NetworkManager.js';
Expand All @@ -32,7 +32,7 @@ import {Target} from './Target.js';
import {TimeoutSettings} from './TimeoutSettings.js';
import {debugError} from './util.js';

const UTILITY_WORLD_NAME = '__puppeteer_utility_world__';
export const UTILITY_WORLD_NAME = '__puppeteer_utility_world__';

/**
* We use symbols to prevent external parties listening to these events.
Expand Down Expand Up @@ -389,11 +389,6 @@ export class FrameManager extends EventEmitter {
return;
}

await session.send('Page.addScriptToEvaluateOnNewDocument', {
source: `//# sourceURL=${EVALUATION_SCRIPT_URL}`,
worldName: name,
});

await Promise.all(
this.frames()
.filter(frame => {
Expand Down
11 changes: 10 additions & 1 deletion src/common/Page.ts
Expand Up @@ -28,7 +28,11 @@ import {ElementHandle} from './ElementHandle.js';
import {EmulationManager} from './EmulationManager.js';
import {EventEmitter, Handler} from './EventEmitter.js';
import {FileChooser} from './FileChooser.js';
import {FrameManager, FrameManagerEmittedEvents} from './FrameManager.js';
import {
FrameManager,
FrameManagerEmittedEvents,
UTILITY_WORLD_NAME,
} from './FrameManager.js';
import {Frame} from './Frame.js';
import {HTTPRequest} from './HTTPRequest.js';
import {HTTPResponse} from './HTTPResponse.js';
Expand Down Expand Up @@ -73,6 +77,7 @@ import {
DeferredPromise,
} from '../util/DeferredPromise.js';
import {WebWorker} from './WebWorker.js';
import {EVALUATION_SCRIPT_URL} from './ExecutionContext.js';

/**
* @public
Expand Down Expand Up @@ -641,6 +646,10 @@ export class Page extends EventEmitter {
this.#frameManager.initialize(this.#target._targetId),
this.#client.send('Performance.enable'),
this.#client.send('Log.enable'),
this.#client.send('Page.addScriptToEvaluateOnNewDocument', {
source: `//# sourceURL=${EVALUATION_SCRIPT_URL}`,
worldName: UTILITY_WORLD_NAME,
}),
]);
}

Expand Down

0 comments on commit c4d9525

Please sign in to comment.