CdpPreloadScript.ts (1066B)
1 /** 2 * @license 3 * Copyright 2024 Google Inc. 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 import type {CdpFrame} from './Frame.js'; 8 9 /** 10 * @internal 11 */ 12 export class CdpPreloadScript { 13 /** 14 * This is the ID of the preload script returned by 15 * Page.addScriptToEvaluateOnNewDocument in the main frame. 16 * 17 * Sub-frames would get a different CDP ID because 18 * addScriptToEvaluateOnNewDocument is called for each subframe. But 19 * users only see this ID and subframe IDs are internal to Puppeteer. 20 */ 21 #id: string; 22 #source: string; 23 #frameToId = new WeakMap<CdpFrame, string>(); 24 25 constructor(mainFrame: CdpFrame, id: string, source: string) { 26 this.#id = id; 27 this.#source = source; 28 this.#frameToId.set(mainFrame, id); 29 } 30 31 get id(): string { 32 return this.#id; 33 } 34 35 get source(): string { 36 return this.#source; 37 } 38 39 getIdForFrame(frame: CdpFrame): string | undefined { 40 return this.#frameToId.get(frame); 41 } 42 43 setIdForFrame(frame: CdpFrame, identifier: string): void { 44 this.#frameToId.set(frame, identifier); 45 } 46 }