mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
feat: Page.removeScriptToEvaluateOnNewDocument (#10250)
Co-authored-by: Alex Rudenko <alexrudenko@chromium.org>
This commit is contained in:
parent
031b021703
commit
b5a124ff73
@ -98,6 +98,7 @@ sidebar_label: API
|
|||||||
| [MouseOptions](./puppeteer.mouseoptions.md) | |
|
| [MouseOptions](./puppeteer.mouseoptions.md) | |
|
||||||
| [MouseWheelOptions](./puppeteer.mousewheeloptions.md) | |
|
| [MouseWheelOptions](./puppeteer.mousewheeloptions.md) | |
|
||||||
| [NetworkConditions](./puppeteer.networkconditions.md) | |
|
| [NetworkConditions](./puppeteer.networkconditions.md) | |
|
||||||
|
| [NewDocumentScriptEvaluation](./puppeteer.newdocumentscriptevaluation.md) | |
|
||||||
| [Offset](./puppeteer.offset.md) | |
|
| [Offset](./puppeteer.offset.md) | |
|
||||||
| [PageEventObject](./puppeteer.pageeventobject.md) | <p>Denotes the objects received by callback functions for page events.</p><p>See [PageEmittedEvents](./puppeteer.pageemittedevents.md) for more detail on the events and when they are emitted.</p> |
|
| [PageEventObject](./puppeteer.pageeventobject.md) | <p>Denotes the objects received by callback functions for page events.</p><p>See [PageEmittedEvents](./puppeteer.pageemittedevents.md) for more detail on the events and when they are emitted.</p> |
|
||||||
| [PDFMargin](./puppeteer.pdfmargin.md) | |
|
| [PDFMargin](./puppeteer.pdfmargin.md) | |
|
||||||
|
17
docs/api/puppeteer.newdocumentscriptevaluation.md
Normal file
17
docs/api/puppeteer.newdocumentscriptevaluation.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
sidebar_label: NewDocumentScriptEvaluation
|
||||||
|
---
|
||||||
|
|
||||||
|
# NewDocumentScriptEvaluation interface
|
||||||
|
|
||||||
|
#### Signature:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
export interface NewDocumentScriptEvaluation
|
||||||
|
```
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
| Property | Modifiers | Type | Description | Default |
|
||||||
|
| ---------- | --------- | ------ | ----------- | ------- |
|
||||||
|
| identifier | | string | | |
|
@ -19,7 +19,10 @@ class Page {
|
|||||||
evaluateOnNewDocument<
|
evaluateOnNewDocument<
|
||||||
Params extends unknown[],
|
Params extends unknown[],
|
||||||
Func extends (...args: Params) => unknown = (...args: Params) => unknown
|
Func extends (...args: Params) => unknown = (...args: Params) => unknown
|
||||||
>(pageFunction: Func | string, ...args: Params): Promise<void>;
|
>(
|
||||||
|
pageFunction: Func | string,
|
||||||
|
...args: Params
|
||||||
|
): Promise<NewDocumentScriptEvaluation>;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -32,7 +35,7 @@ class Page {
|
|||||||
|
|
||||||
**Returns:**
|
**Returns:**
|
||||||
|
|
||||||
Promise<void>
|
Promise<[NewDocumentScriptEvaluation](./puppeteer.newdocumentscriptevaluation.md)>
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
|
@ -74,92 +74,93 @@ page.off('request', logRequest);
|
|||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
||||||
| Method | Modifiers | Description |
|
| Method | Modifiers | Description |
|
||||||
| ------------------------------------------------------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| ---------------------------------------------------------------------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| [$(selector)](./puppeteer.page._.md) | | Runs <code>document.querySelector</code> within the page. If no element matches the selector, the return value resolves to <code>null</code>. |
|
| [$(selector)](./puppeteer.page._.md) | | Runs <code>document.querySelector</code> within the page. If no element matches the selector, the return value resolves to <code>null</code>. |
|
||||||
| [$$(selector)](./puppeteer.page.__.md) | | The method runs <code>document.querySelectorAll</code> within the page. If no elements match the selector, the return value resolves to <code>[]</code>. |
|
| [$$(selector)](./puppeteer.page.__.md) | | The method runs <code>document.querySelectorAll</code> within the page. If no elements match the selector, the return value resolves to <code>[]</code>. |
|
||||||
| [$$eval(selector, pageFunction, args)](./puppeteer.page.__eval.md) | | This method runs <code>Array.from(document.querySelectorAll(selector))</code> within the page and passes the result as the first argument to the <code>pageFunction</code>. |
|
| [$$eval(selector, pageFunction, args)](./puppeteer.page.__eval.md) | | This method runs <code>Array.from(document.querySelectorAll(selector))</code> within the page and passes the result as the first argument to the <code>pageFunction</code>. |
|
||||||
| [$eval(selector, pageFunction, args)](./puppeteer.page._eval.md) | | This method runs <code>document.querySelector</code> within the page and passes the result as the first argument to the <code>pageFunction</code>. |
|
| [$eval(selector, pageFunction, args)](./puppeteer.page._eval.md) | | This method runs <code>document.querySelector</code> within the page and passes the result as the first argument to the <code>pageFunction</code>. |
|
||||||
| [$x(expression)](./puppeteer.page._x.md) | | The method evaluates the XPath expression relative to the page document as its context node. If there are no such elements, the method resolves to an empty array. |
|
| [$x(expression)](./puppeteer.page._x.md) | | The method evaluates the XPath expression relative to the page document as its context node. If there are no such elements, the method resolves to an empty array. |
|
||||||
| [addScriptTag(options)](./puppeteer.page.addscripttag.md) | | Adds a <code><script></code> tag into the page with the desired URL or content. |
|
| [addScriptTag(options)](./puppeteer.page.addscripttag.md) | | Adds a <code><script></code> tag into the page with the desired URL or content. |
|
||||||
| [addStyleTag(options)](./puppeteer.page.addstyletag.md) | | <p>Adds a <code><link rel="stylesheet"></code> tag into the page with the desired URL or a <code><style type="text/css"></code> tag with the content.</p><p>Shortcut for [page.mainFrame().addStyleTag(options)](./puppeteer.frame.addstyletag_1.md).</p> |
|
| [addStyleTag(options)](./puppeteer.page.addstyletag.md) | | <p>Adds a <code><link rel="stylesheet"></code> tag into the page with the desired URL or a <code><style type="text/css"></code> tag with the content.</p><p>Shortcut for [page.mainFrame().addStyleTag(options)](./puppeteer.frame.addstyletag_1.md).</p> |
|
||||||
| [addStyleTag(options)](./puppeteer.page.addstyletag_1.md) | | |
|
| [addStyleTag(options)](./puppeteer.page.addstyletag_1.md) | | |
|
||||||
| [addStyleTag(options)](./puppeteer.page.addstyletag_2.md) | | |
|
| [addStyleTag(options)](./puppeteer.page.addstyletag_2.md) | | |
|
||||||
| [authenticate(credentials)](./puppeteer.page.authenticate.md) | | Provide credentials for <code>HTTP authentication</code>. |
|
| [authenticate(credentials)](./puppeteer.page.authenticate.md) | | Provide credentials for <code>HTTP authentication</code>. |
|
||||||
| [bringToFront()](./puppeteer.page.bringtofront.md) | | Brings page to front (activates tab). |
|
| [bringToFront()](./puppeteer.page.bringtofront.md) | | Brings page to front (activates tab). |
|
||||||
| [browser()](./puppeteer.page.browser.md) | | Get the browser the page belongs to. |
|
| [browser()](./puppeteer.page.browser.md) | | Get the browser the page belongs to. |
|
||||||
| [browserContext()](./puppeteer.page.browsercontext.md) | | Get the browser context that the page belongs to. |
|
| [browserContext()](./puppeteer.page.browsercontext.md) | | Get the browser context that the page belongs to. |
|
||||||
| [click(selector, options)](./puppeteer.page.click.md) | | This method fetches an element with <code>selector</code>, scrolls it into view if needed, and then uses [Page.mouse](./puppeteer.page.md) to click in the center of the element. If there's no element matching <code>selector</code>, the method throws an error. |
|
| [click(selector, options)](./puppeteer.page.click.md) | | This method fetches an element with <code>selector</code>, scrolls it into view if needed, and then uses [Page.mouse](./puppeteer.page.md) to click in the center of the element. If there's no element matching <code>selector</code>, the method throws an error. |
|
||||||
| [close(options)](./puppeteer.page.close.md) | | |
|
| [close(options)](./puppeteer.page.close.md) | | |
|
||||||
| [content()](./puppeteer.page.content.md) | | The full HTML contents of the page, including the DOCTYPE. |
|
| [content()](./puppeteer.page.content.md) | | The full HTML contents of the page, including the DOCTYPE. |
|
||||||
| [cookies(urls)](./puppeteer.page.cookies.md) | | If no URLs are specified, this method returns cookies for the current page URL. If URLs are specified, only cookies for those URLs are returned. |
|
| [cookies(urls)](./puppeteer.page.cookies.md) | | If no URLs are specified, this method returns cookies for the current page URL. If URLs are specified, only cookies for those URLs are returned. |
|
||||||
| [createPDFStream(options)](./puppeteer.page.createpdfstream.md) | | Generates a PDF of the page with the <code>print</code> CSS media type. |
|
| [createPDFStream(options)](./puppeteer.page.createpdfstream.md) | | Generates a PDF of the page with the <code>print</code> CSS media type. |
|
||||||
| [deleteCookie(cookies)](./puppeteer.page.deletecookie.md) | | |
|
| [deleteCookie(cookies)](./puppeteer.page.deletecookie.md) | | |
|
||||||
| [emulate(device)](./puppeteer.page.emulate.md) | | <p>Emulates a given device's metrics and user agent.</p><p>To aid emulation, Puppeteer provides a list of known devices that can be via [KnownDevices](./puppeteer.knowndevices.md).</p> |
|
| [emulate(device)](./puppeteer.page.emulate.md) | | <p>Emulates a given device's metrics and user agent.</p><p>To aid emulation, Puppeteer provides a list of known devices that can be via [KnownDevices](./puppeteer.knowndevices.md).</p> |
|
||||||
| [emulateCPUThrottling(factor)](./puppeteer.page.emulatecputhrottling.md) | | Enables CPU throttling to emulate slow CPUs. |
|
| [emulateCPUThrottling(factor)](./puppeteer.page.emulatecputhrottling.md) | | Enables CPU throttling to emulate slow CPUs. |
|
||||||
| [emulateIdleState(overrides)](./puppeteer.page.emulateidlestate.md) | | Emulates the idle state. If no arguments set, clears idle state emulation. |
|
| [emulateIdleState(overrides)](./puppeteer.page.emulateidlestate.md) | | Emulates the idle state. If no arguments set, clears idle state emulation. |
|
||||||
| [emulateMediaFeatures(features)](./puppeteer.page.emulatemediafeatures.md) | | |
|
| [emulateMediaFeatures(features)](./puppeteer.page.emulatemediafeatures.md) | | |
|
||||||
| [emulateMediaType(type)](./puppeteer.page.emulatemediatype.md) | | |
|
| [emulateMediaType(type)](./puppeteer.page.emulatemediatype.md) | | |
|
||||||
| [emulateNetworkConditions(networkConditions)](./puppeteer.page.emulatenetworkconditions.md) | | <p>This does not affect WebSockets and WebRTC PeerConnections (see https://crbug.com/563644). To set the page offline, you can use [Page.setOfflineMode()](./puppeteer.page.setofflinemode.md).</p><p>A list of predefined network conditions can be used by importing [PredefinedNetworkConditions](./puppeteer.predefinednetworkconditions.md).</p> |
|
| [emulateNetworkConditions(networkConditions)](./puppeteer.page.emulatenetworkconditions.md) | | <p>This does not affect WebSockets and WebRTC PeerConnections (see https://crbug.com/563644). To set the page offline, you can use [Page.setOfflineMode()](./puppeteer.page.setofflinemode.md).</p><p>A list of predefined network conditions can be used by importing [PredefinedNetworkConditions](./puppeteer.predefinednetworkconditions.md).</p> |
|
||||||
| [emulateTimezone(timezoneId)](./puppeteer.page.emulatetimezone.md) | | |
|
| [emulateTimezone(timezoneId)](./puppeteer.page.emulatetimezone.md) | | |
|
||||||
| [emulateVisionDeficiency(type)](./puppeteer.page.emulatevisiondeficiency.md) | | Simulates the given vision deficiency on the page. |
|
| [emulateVisionDeficiency(type)](./puppeteer.page.emulatevisiondeficiency.md) | | Simulates the given vision deficiency on the page. |
|
||||||
| [evaluate(pageFunction, args)](./puppeteer.page.evaluate.md) | | <p>Evaluates a function in the page's context and returns the result.</p><p>If the function passed to <code>page.evaluateHandle</code> returns a Promise, the function will wait for the promise to resolve and return its value.</p> |
|
| [evaluate(pageFunction, args)](./puppeteer.page.evaluate.md) | | <p>Evaluates a function in the page's context and returns the result.</p><p>If the function passed to <code>page.evaluateHandle</code> returns a Promise, the function will wait for the promise to resolve and return its value.</p> |
|
||||||
| [evaluateHandle(pageFunction, args)](./puppeteer.page.evaluatehandle.md) | | |
|
| [evaluateHandle(pageFunction, args)](./puppeteer.page.evaluatehandle.md) | | |
|
||||||
| [evaluateOnNewDocument(pageFunction, args)](./puppeteer.page.evaluateonnewdocument.md) | | <p>Adds a function which would be invoked in one of the following scenarios:</p><p>- whenever the page is navigated</p><p>- whenever the child frame is attached or navigated. In this case, the function is invoked in the context of the newly attached frame.</p><p>The function is invoked after the document was created but before any of its scripts were run. This is useful to amend the JavaScript environment, e.g. to seed <code>Math.random</code>.</p> |
|
| [evaluateOnNewDocument(pageFunction, args)](./puppeteer.page.evaluateonnewdocument.md) | | <p>Adds a function which would be invoked in one of the following scenarios:</p><p>- whenever the page is navigated</p><p>- whenever the child frame is attached or navigated. In this case, the function is invoked in the context of the newly attached frame.</p><p>The function is invoked after the document was created but before any of its scripts were run. This is useful to amend the JavaScript environment, e.g. to seed <code>Math.random</code>.</p> |
|
||||||
| [exposeFunction(name, pptrFunction)](./puppeteer.page.exposefunction.md) | | <p>The method adds a function called <code>name</code> on the page's <code>window</code> object. When called, the function executes <code>puppeteerFunction</code> in node.js and returns a <code>Promise</code> which resolves to the return value of <code>puppeteerFunction</code>.</p><p>If the puppeteerFunction returns a <code>Promise</code>, it will be awaited.</p><p>:::note</p><p>Functions installed via <code>page.exposeFunction</code> survive navigations.</p><p>:::note</p> |
|
| [exposeFunction(name, pptrFunction)](./puppeteer.page.exposefunction.md) | | <p>The method adds a function called <code>name</code> on the page's <code>window</code> object. When called, the function executes <code>puppeteerFunction</code> in node.js and returns a <code>Promise</code> which resolves to the return value of <code>puppeteerFunction</code>.</p><p>If the puppeteerFunction returns a <code>Promise</code>, it will be awaited.</p><p>:::note</p><p>Functions installed via <code>page.exposeFunction</code> survive navigations.</p><p>:::note</p> |
|
||||||
| [focus(selector)](./puppeteer.page.focus.md) | | This method fetches an element with <code>selector</code> and focuses it. If there's no element matching <code>selector</code>, the method throws an error. |
|
| [focus(selector)](./puppeteer.page.focus.md) | | This method fetches an element with <code>selector</code> and focuses it. If there's no element matching <code>selector</code>, the method throws an error. |
|
||||||
| [frames()](./puppeteer.page.frames.md) | | An array of all frames attached to the page. |
|
| [frames()](./puppeteer.page.frames.md) | | An array of all frames attached to the page. |
|
||||||
| [getDefaultTimeout()](./puppeteer.page.getdefaulttimeout.md) | | Maximum time in milliseconds. |
|
| [getDefaultTimeout()](./puppeteer.page.getdefaulttimeout.md) | | Maximum time in milliseconds. |
|
||||||
| [goBack(options)](./puppeteer.page.goback.md) | | This method navigate to the previous page in history. |
|
| [goBack(options)](./puppeteer.page.goback.md) | | This method navigate to the previous page in history. |
|
||||||
| [goForward(options)](./puppeteer.page.goforward.md) | | This method navigate to the next page in history. |
|
| [goForward(options)](./puppeteer.page.goforward.md) | | This method navigate to the next page in history. |
|
||||||
| [goto(url, options)](./puppeteer.page.goto.md) | | |
|
| [goto(url, options)](./puppeteer.page.goto.md) | | |
|
||||||
| [hover(selector)](./puppeteer.page.hover.md) | | This method fetches an element with <code>selector</code>, scrolls it into view if needed, and then uses [Page.mouse](./puppeteer.page.md) to hover over the center of the element. If there's no element matching <code>selector</code>, the method throws an error. |
|
| [hover(selector)](./puppeteer.page.hover.md) | | This method fetches an element with <code>selector</code>, scrolls it into view if needed, and then uses [Page.mouse](./puppeteer.page.md) to hover over the center of the element. If there's no element matching <code>selector</code>, the method throws an error. |
|
||||||
| [isClosed()](./puppeteer.page.isclosed.md) | | Indicates that the page has been closed. |
|
| [isClosed()](./puppeteer.page.isclosed.md) | | Indicates that the page has been closed. |
|
||||||
| [isDragInterceptionEnabled()](./puppeteer.page.isdraginterceptionenabled.md) | | <code>true</code> if drag events are being intercepted, <code>false</code> otherwise. |
|
| [isDragInterceptionEnabled()](./puppeteer.page.isdraginterceptionenabled.md) | | <code>true</code> if drag events are being intercepted, <code>false</code> otherwise. |
|
||||||
| [isJavaScriptEnabled()](./puppeteer.page.isjavascriptenabled.md) | | <code>true</code> if the page has JavaScript enabled, <code>false</code> otherwise. |
|
| [isJavaScriptEnabled()](./puppeteer.page.isjavascriptenabled.md) | | <code>true</code> if the page has JavaScript enabled, <code>false</code> otherwise. |
|
||||||
| [isServiceWorkerBypassed()](./puppeteer.page.isserviceworkerbypassed.md) | | <code>true</code> if the service worker are being bypassed, <code>false</code> otherwise. |
|
| [isServiceWorkerBypassed()](./puppeteer.page.isserviceworkerbypassed.md) | | <code>true</code> if the service worker are being bypassed, <code>false</code> otherwise. |
|
||||||
| [mainFrame()](./puppeteer.page.mainframe.md) | | The page's main frame. |
|
| [mainFrame()](./puppeteer.page.mainframe.md) | | The page's main frame. |
|
||||||
| [metrics()](./puppeteer.page.metrics.md) | | Object containing metrics as key/value pairs. |
|
| [metrics()](./puppeteer.page.metrics.md) | | Object containing metrics as key/value pairs. |
|
||||||
| [off(eventName, handler)](./puppeteer.page.off.md) | | |
|
| [off(eventName, handler)](./puppeteer.page.off.md) | | |
|
||||||
| [on(eventName, handler)](./puppeteer.page.on.md) | | <p>Listen to page events.</p><p>:::note</p><p>This method exists to define event typings and handle proper wireup of cooperative request interception. Actual event listening and dispatching is delegated to [EventEmitter](./puppeteer.eventemitter.md).</p><p>:::</p> |
|
| [on(eventName, handler)](./puppeteer.page.on.md) | | <p>Listen to page events.</p><p>:::note</p><p>This method exists to define event typings and handle proper wireup of cooperative request interception. Actual event listening and dispatching is delegated to [EventEmitter](./puppeteer.eventemitter.md).</p><p>:::</p> |
|
||||||
| [once(eventName, handler)](./puppeteer.page.once.md) | | |
|
| [once(eventName, handler)](./puppeteer.page.once.md) | | |
|
||||||
| [pdf(options)](./puppeteer.page.pdf.md) | | Generates a PDF of the page with the <code>print</code> CSS media type. |
|
| [pdf(options)](./puppeteer.page.pdf.md) | | Generates a PDF of the page with the <code>print</code> CSS media type. |
|
||||||
| [queryObjects(prototypeHandle)](./puppeteer.page.queryobjects.md) | | This method iterates the JavaScript heap and finds all objects with the given prototype. |
|
| [queryObjects(prototypeHandle)](./puppeteer.page.queryobjects.md) | | This method iterates the JavaScript heap and finds all objects with the given prototype. |
|
||||||
| [reload(options)](./puppeteer.page.reload.md) | | |
|
| [reload(options)](./puppeteer.page.reload.md) | | |
|
||||||
| [screenshot(options)](./puppeteer.page.screenshot.md) | | Captures screenshot of the current page. |
|
| [removeScriptToEvaluateOnNewDocument(identifier)](./puppeteer.page.removescripttoevaluateonnewdocument.md) | | Removes script that injected into page by Page.evaluateOnNewDocument. |
|
||||||
| [screenshot(options)](./puppeteer.page.screenshot_1.md) | | |
|
| [screenshot(options)](./puppeteer.page.screenshot.md) | | Captures screenshot of the current page. |
|
||||||
| [screenshot(options)](./puppeteer.page.screenshot_2.md) | | |
|
| [screenshot(options)](./puppeteer.page.screenshot_1.md) | | |
|
||||||
| [select(selector, values)](./puppeteer.page.select.md) | | Triggers a <code>change</code> and <code>input</code> event once all the provided options have been selected. If there's no <code><select></code> element matching <code>selector</code>, the method throws an error. |
|
| [screenshot(options)](./puppeteer.page.screenshot_2.md) | | |
|
||||||
| [setBypassCSP(enabled)](./puppeteer.page.setbypasscsp.md) | | Toggles bypassing page's Content-Security-Policy. |
|
| [select(selector, values)](./puppeteer.page.select.md) | | Triggers a <code>change</code> and <code>input</code> event once all the provided options have been selected. If there's no <code><select></code> element matching <code>selector</code>, the method throws an error. |
|
||||||
| [setBypassServiceWorker(bypass)](./puppeteer.page.setbypassserviceworker.md) | | Toggles ignoring of service worker for each request. |
|
| [setBypassCSP(enabled)](./puppeteer.page.setbypasscsp.md) | | Toggles bypassing page's Content-Security-Policy. |
|
||||||
| [setCacheEnabled(enabled)](./puppeteer.page.setcacheenabled.md) | | Toggles ignoring cache for each request based on the enabled state. By default, caching is enabled. |
|
| [setBypassServiceWorker(bypass)](./puppeteer.page.setbypassserviceworker.md) | | Toggles ignoring of service worker for each request. |
|
||||||
| [setContent(html, options)](./puppeteer.page.setcontent.md) | | Set the content of the page. |
|
| [setCacheEnabled(enabled)](./puppeteer.page.setcacheenabled.md) | | Toggles ignoring cache for each request based on the enabled state. By default, caching is enabled. |
|
||||||
| [setCookie(cookies)](./puppeteer.page.setcookie.md) | | |
|
| [setContent(html, options)](./puppeteer.page.setcontent.md) | | Set the content of the page. |
|
||||||
| [setDefaultNavigationTimeout(timeout)](./puppeteer.page.setdefaultnavigationtimeout.md) | | <p>This setting will change the default maximum navigation time for the following methods and related shortcuts:</p><p>- [page.goBack(options)](./puppeteer.page.goback.md)</p><p>- [page.goForward(options)](./puppeteer.page.goforward.md)</p><p>- [page.goto(url,options)](./puppeteer.page.goto.md)</p><p>- [page.reload(options)](./puppeteer.page.reload.md)</p><p>- [page.setContent(html,options)](./puppeteer.page.setcontent.md)</p><p>- [page.waitForNavigation(options)](./puppeteer.page.waitfornavigation.md)</p> |
|
| [setCookie(cookies)](./puppeteer.page.setcookie.md) | | |
|
||||||
| [setDefaultTimeout(timeout)](./puppeteer.page.setdefaulttimeout.md) | | |
|
| [setDefaultNavigationTimeout(timeout)](./puppeteer.page.setdefaultnavigationtimeout.md) | | <p>This setting will change the default maximum navigation time for the following methods and related shortcuts:</p><p>- [page.goBack(options)](./puppeteer.page.goback.md)</p><p>- [page.goForward(options)](./puppeteer.page.goforward.md)</p><p>- [page.goto(url,options)](./puppeteer.page.goto.md)</p><p>- [page.reload(options)](./puppeteer.page.reload.md)</p><p>- [page.setContent(html,options)](./puppeteer.page.setcontent.md)</p><p>- [page.waitForNavigation(options)](./puppeteer.page.waitfornavigation.md)</p> |
|
||||||
| [setDragInterception(enabled)](./puppeteer.page.setdraginterception.md) | | |
|
| [setDefaultTimeout(timeout)](./puppeteer.page.setdefaulttimeout.md) | | |
|
||||||
| [setExtraHTTPHeaders(headers)](./puppeteer.page.setextrahttpheaders.md) | | <p>The extra HTTP headers will be sent with every request the page initiates.</p><p>:::tip</p><p>All HTTP header names are lowercased. (HTTP headers are case-insensitive, so this shouldn’t impact your server code.)</p><p>:::</p><p>:::note</p><p>page.setExtraHTTPHeaders does not guarantee the order of headers in the outgoing requests.</p><p>:::</p> |
|
| [setDragInterception(enabled)](./puppeteer.page.setdraginterception.md) | | |
|
||||||
| [setGeolocation(options)](./puppeteer.page.setgeolocation.md) | | Sets the page's geolocation. |
|
| [setExtraHTTPHeaders(headers)](./puppeteer.page.setextrahttpheaders.md) | | <p>The extra HTTP headers will be sent with every request the page initiates.</p><p>:::tip</p><p>All HTTP header names are lowercased. (HTTP headers are case-insensitive, so this shouldn’t impact your server code.)</p><p>:::</p><p>:::note</p><p>page.setExtraHTTPHeaders does not guarantee the order of headers in the outgoing requests.</p><p>:::</p> |
|
||||||
| [setJavaScriptEnabled(enabled)](./puppeteer.page.setjavascriptenabled.md) | | |
|
| [setGeolocation(options)](./puppeteer.page.setgeolocation.md) | | Sets the page's geolocation. |
|
||||||
| [setOfflineMode(enabled)](./puppeteer.page.setofflinemode.md) | | <p>Sets the network connection to offline.</p><p>It does not change the parameters used in [Page.emulateNetworkConditions()](./puppeteer.page.emulatenetworkconditions.md)</p> |
|
| [setJavaScriptEnabled(enabled)](./puppeteer.page.setjavascriptenabled.md) | | |
|
||||||
| [setRequestInterception(value)](./puppeteer.page.setrequestinterception.md) | | <p>Activating request interception enables [HTTPRequest.abort()](./puppeteer.httprequest.abort.md), [HTTPRequest.continue()](./puppeteer.httprequest.continue.md) and [HTTPRequest.respond()](./puppeteer.httprequest.respond.md) methods. This provides the capability to modify network requests that are made by a page.</p><p>Once request interception is enabled, every request will stall unless it's continued, responded or aborted; or completed using the browser cache.</p><p>See the [Request interception guide](https://pptr.dev/next/guides/request-interception) for more details.</p> |
|
| [setOfflineMode(enabled)](./puppeteer.page.setofflinemode.md) | | <p>Sets the network connection to offline.</p><p>It does not change the parameters used in [Page.emulateNetworkConditions()](./puppeteer.page.emulatenetworkconditions.md)</p> |
|
||||||
| [setUserAgent(userAgent, userAgentMetadata)](./puppeteer.page.setuseragent.md) | | |
|
| [setRequestInterception(value)](./puppeteer.page.setrequestinterception.md) | | <p>Activating request interception enables [HTTPRequest.abort()](./puppeteer.httprequest.abort.md), [HTTPRequest.continue()](./puppeteer.httprequest.continue.md) and [HTTPRequest.respond()](./puppeteer.httprequest.respond.md) methods. This provides the capability to modify network requests that are made by a page.</p><p>Once request interception is enabled, every request will stall unless it's continued, responded or aborted; or completed using the browser cache.</p><p>See the [Request interception guide](https://pptr.dev/next/guides/request-interception) for more details.</p> |
|
||||||
| [setViewport(viewport)](./puppeteer.page.setviewport.md) | | <p><code>page.setViewport</code> will resize the page. A lot of websites don't expect phones to change size, so you should set the viewport before navigating to the page.</p><p>In the case of multiple pages in a single browser, each page can have its own viewport size.</p> |
|
| [setUserAgent(userAgent, userAgentMetadata)](./puppeteer.page.setuseragent.md) | | |
|
||||||
| [tap(selector)](./puppeteer.page.tap.md) | | This method fetches an element with <code>selector</code>, scrolls it into view if needed, and then uses [Page.touchscreen](./puppeteer.page.md) to tap in the center of the element. If there's no element matching <code>selector</code>, the method throws an error. |
|
| [setViewport(viewport)](./puppeteer.page.setviewport.md) | | <p><code>page.setViewport</code> will resize the page. A lot of websites don't expect phones to change size, so you should set the viewport before navigating to the page.</p><p>In the case of multiple pages in a single browser, each page can have its own viewport size.</p> |
|
||||||
| [target()](./puppeteer.page.target.md) | | A target this page was created from. |
|
| [tap(selector)](./puppeteer.page.tap.md) | | This method fetches an element with <code>selector</code>, scrolls it into view if needed, and then uses [Page.touchscreen](./puppeteer.page.md) to tap in the center of the element. If there's no element matching <code>selector</code>, the method throws an error. |
|
||||||
| [title()](./puppeteer.page.title.md) | | The page's title |
|
| [target()](./puppeteer.page.target.md) | | A target this page was created from. |
|
||||||
| [type(selector, text, options)](./puppeteer.page.type.md) | | <p>Sends a <code>keydown</code>, <code>keypress/input</code>, and <code>keyup</code> event for each character in the text.</p><p>To press a special key, like <code>Control</code> or <code>ArrowDown</code>, use [Keyboard.press()](./puppeteer.keyboard.press.md).</p> |
|
| [title()](./puppeteer.page.title.md) | | The page's title |
|
||||||
| [url()](./puppeteer.page.url.md) | | The page's URL. |
|
| [type(selector, text, options)](./puppeteer.page.type.md) | | <p>Sends a <code>keydown</code>, <code>keypress/input</code>, and <code>keyup</code> event for each character in the text.</p><p>To press a special key, like <code>Control</code> or <code>ArrowDown</code>, use [Keyboard.press()](./puppeteer.keyboard.press.md).</p> |
|
||||||
| [viewport()](./puppeteer.page.viewport.md) | | Current page viewport settings. |
|
| [url()](./puppeteer.page.url.md) | | The page's URL. |
|
||||||
| [waitForDevicePrompt(options)](./puppeteer.page.waitfordeviceprompt.md) | | <p>This method is typically coupled with an action that triggers a device request from an api such as WebBluetooth.</p><p>:::caution</p><p>This must be called before the device request is made. It will not return a currently active device prompt.</p><p>:::</p> |
|
| [viewport()](./puppeteer.page.viewport.md) | | Current page viewport settings. |
|
||||||
| [waitForFileChooser(options)](./puppeteer.page.waitforfilechooser.md) | | <p>This method is typically coupled with an action that triggers file choosing.</p><p>:::caution</p><p>This must be called before the file chooser is launched. It will not return a currently active file chooser.</p><p>:::</p> |
|
| [waitForDevicePrompt(options)](./puppeteer.page.waitfordeviceprompt.md) | | <p>This method is typically coupled with an action that triggers a device request from an api such as WebBluetooth.</p><p>:::caution</p><p>This must be called before the device request is made. It will not return a currently active device prompt.</p><p>:::</p> |
|
||||||
| [waitForFrame(urlOrPredicate, options)](./puppeteer.page.waitforframe.md) | | |
|
| [waitForFileChooser(options)](./puppeteer.page.waitforfilechooser.md) | | <p>This method is typically coupled with an action that triggers file choosing.</p><p>:::caution</p><p>This must be called before the file chooser is launched. It will not return a currently active file chooser.</p><p>:::</p> |
|
||||||
| [waitForFunction(pageFunction, options, args)](./puppeteer.page.waitforfunction.md) | | Waits for a function to finish evaluating in the page's context. |
|
| [waitForFrame(urlOrPredicate, options)](./puppeteer.page.waitforframe.md) | | |
|
||||||
| [waitForNavigation(options)](./puppeteer.page.waitfornavigation.md) | | Waits for the page to navigate to a new URL or to reload. It is useful when you run code that will indirectly cause the page to navigate. |
|
| [waitForFunction(pageFunction, options, args)](./puppeteer.page.waitforfunction.md) | | Waits for a function to finish evaluating in the page's context. |
|
||||||
| [waitForNetworkIdle(options)](./puppeteer.page.waitfornetworkidle.md) | | |
|
| [waitForNavigation(options)](./puppeteer.page.waitfornavigation.md) | | Waits for the page to navigate to a new URL or to reload. It is useful when you run code that will indirectly cause the page to navigate. |
|
||||||
| [waitForRequest(urlOrPredicate, options)](./puppeteer.page.waitforrequest.md) | | |
|
| [waitForNetworkIdle(options)](./puppeteer.page.waitfornetworkidle.md) | | |
|
||||||
| [waitForResponse(urlOrPredicate, options)](./puppeteer.page.waitforresponse.md) | | |
|
| [waitForRequest(urlOrPredicate, options)](./puppeteer.page.waitforrequest.md) | | |
|
||||||
| [waitForSelector(selector, options)](./puppeteer.page.waitforselector.md) | | Wait for the <code>selector</code> to appear in page. If at the moment of calling the method the <code>selector</code> already exists, the method will return immediately. If the <code>selector</code> doesn't appear after the <code>timeout</code> milliseconds of waiting, the function will throw. |
|
| [waitForResponse(urlOrPredicate, options)](./puppeteer.page.waitforresponse.md) | | |
|
||||||
| [waitForTimeout(milliseconds)](./puppeteer.page.waitfortimeout.md) | | |
|
| [waitForSelector(selector, options)](./puppeteer.page.waitforselector.md) | | Wait for the <code>selector</code> to appear in page. If at the moment of calling the method the <code>selector</code> already exists, the method will return immediately. If the <code>selector</code> doesn't appear after the <code>timeout</code> milliseconds of waiting, the function will throw. |
|
||||||
| [waitForXPath(xpath, options)](./puppeteer.page.waitforxpath.md) | | Wait for the <code>xpath</code> to appear in page. If at the moment of calling the method the <code>xpath</code> already exists, the method will return immediately. If the <code>xpath</code> doesn't appear after the <code>timeout</code> milliseconds of waiting, the function will throw. |
|
| [waitForTimeout(milliseconds)](./puppeteer.page.waitfortimeout.md) | | |
|
||||||
| [workers()](./puppeteer.page.workers.md) | | All of the dedicated [WebWorkers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) associated with the page. |
|
| [waitForXPath(xpath, options)](./puppeteer.page.waitforxpath.md) | | Wait for the <code>xpath</code> to appear in page. If at the moment of calling the method the <code>xpath</code> already exists, the method will return immediately. If the <code>xpath</code> doesn't appear after the <code>timeout</code> milliseconds of waiting, the function will throw. |
|
||||||
|
| [workers()](./puppeteer.page.workers.md) | | All of the dedicated [WebWorkers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) associated with the page. |
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
---
|
||||||
|
sidebar_label: Page.removeScriptToEvaluateOnNewDocument
|
||||||
|
---
|
||||||
|
|
||||||
|
# Page.removeScriptToEvaluateOnNewDocument() method
|
||||||
|
|
||||||
|
Removes script that injected into page by Page.evaluateOnNewDocument.
|
||||||
|
|
||||||
|
#### Signature:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
class Page {
|
||||||
|
removeScriptToEvaluateOnNewDocument(identifier: string): Promise<void>;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| ---------- | ------ | ----------------- |
|
||||||
|
| identifier | string | script identifier |
|
||||||
|
|
||||||
|
**Returns:**
|
||||||
|
|
||||||
|
Promise<void>
|
@ -386,6 +386,13 @@ export interface PageEventObject {
|
|||||||
workerdestroyed: WebWorker;
|
workerdestroyed: WebWorker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export interface NewDocumentScriptEvaluation {
|
||||||
|
identifier: string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Page provides methods to interact with a single tab or
|
* Page provides methods to interact with a single tab or
|
||||||
* {@link https://developer.chrome.com/extensions/background_pages | extension background page}
|
* {@link https://developer.chrome.com/extensions/background_pages | extension background page}
|
||||||
@ -2109,8 +2116,21 @@ export class Page extends EventEmitter {
|
|||||||
async evaluateOnNewDocument<
|
async evaluateOnNewDocument<
|
||||||
Params extends unknown[],
|
Params extends unknown[],
|
||||||
Func extends (...args: Params) => unknown = (...args: Params) => unknown
|
Func extends (...args: Params) => unknown = (...args: Params) => unknown
|
||||||
>(pageFunction: Func | string, ...args: Params): Promise<void>;
|
>(
|
||||||
async evaluateOnNewDocument(): Promise<void> {
|
pageFunction: Func | string,
|
||||||
|
...args: Params
|
||||||
|
): Promise<NewDocumentScriptEvaluation>;
|
||||||
|
async evaluateOnNewDocument(): Promise<NewDocumentScriptEvaluation> {
|
||||||
|
throw new Error('Not implemented');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes script that injected into page by Page.evaluateOnNewDocument.
|
||||||
|
*
|
||||||
|
* @param identifier - script identifier
|
||||||
|
*/
|
||||||
|
async removeScriptToEvaluateOnNewDocument(identifier: string): Promise<void>;
|
||||||
|
async removeScriptToEvaluateOnNewDocument(): Promise<void> {
|
||||||
throw new Error('Not implemented');
|
throw new Error('Not implemented');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ import {
|
|||||||
ScreenshotOptions,
|
ScreenshotOptions,
|
||||||
WaitForOptions,
|
WaitForOptions,
|
||||||
WaitTimeoutOptions,
|
WaitTimeoutOptions,
|
||||||
|
NewDocumentScriptEvaluation,
|
||||||
} from '../api/Page.js';
|
} from '../api/Page.js';
|
||||||
import {assert} from '../util/assert.js';
|
import {assert} from '../util/assert.js';
|
||||||
import {
|
import {
|
||||||
@ -1288,10 +1289,26 @@ export class CDPPage extends Page {
|
|||||||
override async evaluateOnNewDocument<
|
override async evaluateOnNewDocument<
|
||||||
Params extends unknown[],
|
Params extends unknown[],
|
||||||
Func extends (...args: Params) => unknown = (...args: Params) => unknown
|
Func extends (...args: Params) => unknown = (...args: Params) => unknown
|
||||||
>(pageFunction: Func | string, ...args: Params): Promise<void> {
|
>(
|
||||||
|
pageFunction: Func | string,
|
||||||
|
...args: Params
|
||||||
|
): Promise<NewDocumentScriptEvaluation> {
|
||||||
const source = evaluationString(pageFunction, ...args);
|
const source = evaluationString(pageFunction, ...args);
|
||||||
await this.#client.send('Page.addScriptToEvaluateOnNewDocument', {
|
const {identifier} = await this.#client.send(
|
||||||
source,
|
'Page.addScriptToEvaluateOnNewDocument',
|
||||||
|
{
|
||||||
|
source,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return {identifier};
|
||||||
|
}
|
||||||
|
|
||||||
|
override async removeScriptToEvaluateOnNewDocument(
|
||||||
|
identifier: string
|
||||||
|
): Promise<void> {
|
||||||
|
await this.#client.send('Page.removeScriptToEvaluateOnNewDocument', {
|
||||||
|
identifier,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,18 @@
|
|||||||
"parameters": ["webDriverBiDi"],
|
"parameters": ["webDriverBiDi"],
|
||||||
"expectations": ["PASS"]
|
"expectations": ["PASS"]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"testIdPattern": "[evaluation.spec] Evaluation specs Page.evaluateOnNewDocument *",
|
||||||
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
|
"parameters": ["webDriverBiDi"],
|
||||||
|
"expectations": ["SKIP"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"testIdPattern": "[evaluation.spec] Evaluation specs Page.removeScriptToEvaluateOnNewDocument *",
|
||||||
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
|
"parameters": ["webDriverBiDi"],
|
||||||
|
"expectations": ["SKIP"]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"testIdPattern": "[EventEmitter.spec] EventEmitter *",
|
"testIdPattern": "[EventEmitter.spec] EventEmitter *",
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
@ -294,15 +306,15 @@
|
|||||||
"expectations": ["SKIP"]
|
"expectations": ["SKIP"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"testIdPattern": "[evaluation.spec] Evaluation specs Page.evaluateOnNewDocument should evaluate before anything else on the page",
|
"testIdPattern": "[evaluation.spec] Evaluation specs Page.evaluateOnNewDocument *",
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
"parameters": ["webDriverBiDi"],
|
"parameters": ["cdp", "firefox"],
|
||||||
"expectations": ["SKIP"]
|
"expectations": ["SKIP"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"testIdPattern": "[evaluation.spec] Evaluation specs Page.evaluateOnNewDocument should work with CSP",
|
"testIdPattern": "[evaluation.spec] Evaluation specs Page.removeScriptToEvaluateOnNewDocument *",
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
"parameters": ["webDriverBiDi"],
|
"parameters": ["cdp", "firefox"],
|
||||||
"expectations": ["SKIP"]
|
"expectations": ["SKIP"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -905,18 +917,6 @@
|
|||||||
"parameters": ["cdp", "firefox"],
|
"parameters": ["cdp", "firefox"],
|
||||||
"expectations": ["SKIP"]
|
"expectations": ["SKIP"]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"testIdPattern": "[evaluation.spec] Evaluation specs Page.evaluateOnNewDocument should evaluate before anything else on the page",
|
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
|
||||||
"parameters": ["cdp", "firefox"],
|
|
||||||
"expectations": ["SKIP"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"testIdPattern": "[evaluation.spec] Evaluation specs Page.evaluateOnNewDocument should work with CSP",
|
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
|
||||||
"parameters": ["cdp", "firefox"],
|
|
||||||
"expectations": ["FAIL"]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"testIdPattern": "[fixtures.spec] Fixtures dumpio option should work with pipe option",
|
"testIdPattern": "[fixtures.spec] Fixtures dumpio option should work with pipe option",
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
|
@ -537,6 +537,30 @@ describe('Evaluation specs', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Page.removeScriptToEvaluateOnNewDocument', function () {
|
||||||
|
it('should remove new document script', async () => {
|
||||||
|
const {page, server} = getTestState();
|
||||||
|
|
||||||
|
const {identifier} = await page.evaluateOnNewDocument(function () {
|
||||||
|
(globalThis as any).injected = 123;
|
||||||
|
});
|
||||||
|
await page.goto(server.PREFIX + '/tamperable.html');
|
||||||
|
expect(
|
||||||
|
await page.evaluate(() => {
|
||||||
|
return (globalThis as any).result;
|
||||||
|
})
|
||||||
|
).toBe(123);
|
||||||
|
|
||||||
|
await page.removeScriptToEvaluateOnNewDocument(identifier);
|
||||||
|
await page.reload();
|
||||||
|
expect(
|
||||||
|
await page.evaluate(() => {
|
||||||
|
return (globalThis as any).result || null;
|
||||||
|
})
|
||||||
|
).toBe(null);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Frame.evaluate', function () {
|
describe('Frame.evaluate', function () {
|
||||||
it('should have different execution contexts', async () => {
|
it('should have different execution contexts', async () => {
|
||||||
const {page, server} = getTestState();
|
const {page, server} = getTestState();
|
||||||
|
Loading…
Reference in New Issue
Block a user