puppeteer-core
Advanced tools
Comparing version 14.0.0 to 14.1.0
@@ -49,2 +49,6 @@ /** | ||
/** | ||
* @internal | ||
*/ | ||
export declare type IsPageTargetCallback = (target: Protocol.Target.TargetInfo) => boolean; | ||
/** | ||
* @public | ||
@@ -157,3 +161,3 @@ */ | ||
*/ | ||
static create(connection: Connection, contextIds: string[], ignoreHTTPSErrors: boolean, defaultViewport?: Viewport | null, process?: ChildProcess, closeCallback?: BrowserCloseCallback, targetFilterCallback?: TargetFilterCallback): Promise<Browser>; | ||
static create(connection: Connection, contextIds: string[], ignoreHTTPSErrors: boolean, defaultViewport?: Viewport | null, process?: ChildProcess, closeCallback?: BrowserCloseCallback, targetFilterCallback?: TargetFilterCallback, isPageTargetCallback?: IsPageTargetCallback): Promise<Browser>; | ||
private _ignoreHTTPSErrors; | ||
@@ -165,2 +169,3 @@ private _defaultViewport?; | ||
private _targetFilterCallback; | ||
private _isPageTargetCallback; | ||
private _defaultContext; | ||
@@ -178,3 +183,3 @@ private _contexts; | ||
*/ | ||
constructor(connection: Connection, contextIds: string[], ignoreHTTPSErrors: boolean, defaultViewport?: Viewport | null, process?: ChildProcess, closeCallback?: BrowserCloseCallback, targetFilterCallback?: TargetFilterCallback); | ||
constructor(connection: Connection, contextIds: string[], ignoreHTTPSErrors: boolean, defaultViewport?: Viewport | null, process?: ChildProcess, closeCallback?: BrowserCloseCallback, targetFilterCallback?: TargetFilterCallback, isPageTargetCallback?: IsPageTargetCallback); | ||
/** | ||
@@ -186,2 +191,6 @@ * The spawned browser process. Returns `null` if the browser instance was created with | ||
/** | ||
* @internal | ||
*/ | ||
_setIsPageTargetCallback(isPageTargetCallback?: IsPageTargetCallback): void; | ||
/** | ||
* Creates a new incognito browser context. This won't share cookies/cache with other | ||
@@ -188,0 +197,0 @@ * browser contexts. |
@@ -96,3 +96,3 @@ "use strict"; | ||
*/ | ||
constructor(connection, contextIds, ignoreHTTPSErrors, defaultViewport, process, closeCallback, targetFilterCallback) { | ||
constructor(connection, contextIds, ignoreHTTPSErrors, defaultViewport, process, closeCallback, targetFilterCallback, isPageTargetCallback) { | ||
super(); | ||
@@ -107,2 +107,3 @@ this._ignoredTargets = new Set(); | ||
this._targetFilterCallback = targetFilterCallback || (() => true); | ||
this._setIsPageTargetCallback(isPageTargetCallback); | ||
this._defaultContext = new BrowserContext(this._connection, this); | ||
@@ -121,4 +122,4 @@ this._contexts = new Map(); | ||
*/ | ||
static async create(connection, contextIds, ignoreHTTPSErrors, defaultViewport, process, closeCallback, targetFilterCallback) { | ||
const browser = new Browser(connection, contextIds, ignoreHTTPSErrors, defaultViewport, process, closeCallback, targetFilterCallback); | ||
static async create(connection, contextIds, ignoreHTTPSErrors, defaultViewport, process, closeCallback, targetFilterCallback, isPageTargetCallback) { | ||
const browser = new Browser(connection, contextIds, ignoreHTTPSErrors, defaultViewport, process, closeCallback, targetFilterCallback, isPageTargetCallback); | ||
await connection.send('Target.setDiscoverTargets', { discover: true }); | ||
@@ -136,2 +137,14 @@ return browser; | ||
/** | ||
* @internal | ||
*/ | ||
_setIsPageTargetCallback(isPageTargetCallback) { | ||
this._isPageTargetCallback = | ||
isPageTargetCallback || | ||
((target) => { | ||
return (target.type === 'page' || | ||
target.type === 'background_page' || | ||
target.type === 'webview'); | ||
}); | ||
} | ||
/** | ||
* Creates a new incognito browser context. This won't share cookies/cache with other | ||
@@ -204,3 +217,3 @@ * browser contexts. | ||
} | ||
const target = new Target_js_1.Target(targetInfo, context, () => this._connection.createSession(targetInfo), this._ignoreHTTPSErrors, (_a = this._defaultViewport) !== null && _a !== void 0 ? _a : null, this._screenshotTaskQueue); | ||
const target = new Target_js_1.Target(targetInfo, context, () => this._connection.createSession(targetInfo), this._ignoreHTTPSErrors, (_a = this._defaultViewport) !== null && _a !== void 0 ? _a : null, this._screenshotTaskQueue, this._isPageTargetCallback); | ||
(0, assert_js_1.assert)(!this._targets.has(event.targetInfo.targetId), 'Target should not exist before targetCreated'); | ||
@@ -207,0 +220,0 @@ this._targets.set(event.targetInfo.targetId, target); |
@@ -17,3 +17,3 @@ /** | ||
import { ConnectionTransport } from './ConnectionTransport.js'; | ||
import { Browser, TargetFilterCallback } from './Browser.js'; | ||
import { Browser, TargetFilterCallback, IsPageTargetCallback } from './Browser.js'; | ||
import { Viewport } from './PuppeteerViewport.js'; | ||
@@ -44,2 +44,6 @@ /** | ||
targetFilter?: TargetFilterCallback; | ||
/** | ||
* @internal | ||
*/ | ||
isPageTarget?: IsPageTargetCallback; | ||
} | ||
@@ -46,0 +50,0 @@ /** |
@@ -60,3 +60,3 @@ "use strict"; | ||
const connectToBrowser = async (options) => { | ||
const { browserWSEndpoint, browserURL, ignoreHTTPSErrors = false, defaultViewport = { width: 800, height: 600 }, transport, slowMo = 0, targetFilter, } = options; | ||
const { browserWSEndpoint, browserURL, ignoreHTTPSErrors = false, defaultViewport = { width: 800, height: 600 }, transport, slowMo = 0, targetFilter, isPageTarget, } = options; | ||
(0, assert_js_1.assert)(Number(!!browserWSEndpoint) + Number(!!browserURL) + Number(!!transport) === | ||
@@ -80,3 +80,3 @@ 1, 'Exactly one of browserWSEndpoint, browserURL or transport must be passed to puppeteer.connect'); | ||
const { browserContextIds } = await connection.send('Target.getBrowserContexts'); | ||
return Browser_js_1.Browser.create(connection, browserContextIds, ignoreHTTPSErrors, defaultViewport, null, () => connection.send('Browser.close').catch(helper_js_1.debugError), targetFilter); | ||
return Browser_js_1.Browser.create(connection, browserContextIds, ignoreHTTPSErrors, defaultViewport, null, () => connection.send('Browser.close').catch(helper_js_1.debugError), targetFilter, isPageTarget); | ||
}; | ||
@@ -83,0 +83,0 @@ exports.connectToBrowser = connectToBrowser; |
@@ -268,2 +268,57 @@ /** | ||
}): Promise<ElementHandle | null>; | ||
/** | ||
* Wait for the `xpath` within the element. If at the moment of calling the | ||
* method the `xpath` already exists, the method will return immediately. If | ||
* the `xpath` doesn't appear after the `timeout` milliseconds of waiting, the | ||
* function will throw. | ||
* | ||
* If `xpath` starts with `//` instead of `.//`, the dot will be appended automatically. | ||
* | ||
* This method works across navigation | ||
* ```js | ||
* const puppeteer = require('puppeteer'); | ||
* (async () => { | ||
* const browser = await puppeteer.launch(); | ||
* const page = await browser.newPage(); | ||
* let currentURL; | ||
* page | ||
* .waitForXPath('//img') | ||
* .then(() => console.log('First URL with image: ' + currentURL)); | ||
* for (currentURL of [ | ||
* 'https://example.com', | ||
* 'https://google.com', | ||
* 'https://bbc.com', | ||
* ]) { | ||
* await page.goto(currentURL); | ||
* } | ||
* await browser.close(); | ||
* })(); | ||
* ``` | ||
* @param xpath - A | ||
* {@link https://developer.mozilla.org/en-US/docs/Web/XPath | xpath} of an | ||
* element to wait for | ||
* @param options - Optional waiting parameters | ||
* @returns Promise which resolves when element specified by xpath string is | ||
* added to DOM. Resolves to `null` if waiting for `hidden: true` and xpath is | ||
* not found in DOM. | ||
* @remarks | ||
* The optional Argument `options` have properties: | ||
* | ||
* - `visible`: A boolean to wait for element to be present in DOM and to be | ||
* visible, i.e. to not have `display: none` or `visibility: hidden` CSS | ||
* properties. Defaults to `false`. | ||
* | ||
* - `hidden`: A boolean wait for element to not be found in the DOM or to be | ||
* hidden, i.e. have `display: none` or `visibility: hidden` CSS properties. | ||
* Defaults to `false`. | ||
* | ||
* - `timeout`: A number which is maximum time to wait for in milliseconds. | ||
* Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default | ||
* value can be changed by using the {@link Page.setDefaultTimeout} method. | ||
*/ | ||
waitForXPath(xpath: string, options?: { | ||
visible?: boolean; | ||
hidden?: boolean; | ||
timeout?: number; | ||
}): Promise<ElementHandle | null>; | ||
asElement(): ElementHandle<ElementType> | null; | ||
@@ -270,0 +325,0 @@ /** |
@@ -318,2 +318,73 @@ "use strict"; | ||
} | ||
/** | ||
* Wait for the `xpath` within the element. If at the moment of calling the | ||
* method the `xpath` already exists, the method will return immediately. If | ||
* the `xpath` doesn't appear after the `timeout` milliseconds of waiting, the | ||
* function will throw. | ||
* | ||
* If `xpath` starts with `//` instead of `.//`, the dot will be appended automatically. | ||
* | ||
* This method works across navigation | ||
* ```js | ||
* const puppeteer = require('puppeteer'); | ||
* (async () => { | ||
* const browser = await puppeteer.launch(); | ||
* const page = await browser.newPage(); | ||
* let currentURL; | ||
* page | ||
* .waitForXPath('//img') | ||
* .then(() => console.log('First URL with image: ' + currentURL)); | ||
* for (currentURL of [ | ||
* 'https://example.com', | ||
* 'https://google.com', | ||
* 'https://bbc.com', | ||
* ]) { | ||
* await page.goto(currentURL); | ||
* } | ||
* await browser.close(); | ||
* })(); | ||
* ``` | ||
* @param xpath - A | ||
* {@link https://developer.mozilla.org/en-US/docs/Web/XPath | xpath} of an | ||
* element to wait for | ||
* @param options - Optional waiting parameters | ||
* @returns Promise which resolves when element specified by xpath string is | ||
* added to DOM. Resolves to `null` if waiting for `hidden: true` and xpath is | ||
* not found in DOM. | ||
* @remarks | ||
* The optional Argument `options` have properties: | ||
* | ||
* - `visible`: A boolean to wait for element to be present in DOM and to be | ||
* visible, i.e. to not have `display: none` or `visibility: hidden` CSS | ||
* properties. Defaults to `false`. | ||
* | ||
* - `hidden`: A boolean wait for element to not be found in the DOM or to be | ||
* hidden, i.e. have `display: none` or `visibility: hidden` CSS properties. | ||
* Defaults to `false`. | ||
* | ||
* - `timeout`: A number which is maximum time to wait for in milliseconds. | ||
* Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default | ||
* value can be changed by using the {@link Page.setDefaultTimeout} method. | ||
*/ | ||
async waitForXPath(xpath, options = {}) { | ||
const frame = this._context.frame(); | ||
const secondaryContext = await frame._secondaryWorld.executionContext(); | ||
const adoptedRoot = await secondaryContext._adoptElementHandle(this); | ||
xpath = xpath.startsWith('//') ? '.' + xpath : xpath; | ||
if (!xpath.startsWith('.//')) { | ||
await adoptedRoot.dispose(); | ||
throw new Error('Unsupported xpath expression: ' + xpath); | ||
} | ||
const handle = await frame._secondaryWorld.waitForXPath(xpath, { | ||
...options, | ||
root: adoptedRoot, | ||
}); | ||
await adoptedRoot.dispose(); | ||
if (!handle) | ||
return null; | ||
const mainExecutionContext = await frame._mainWorld.executionContext(); | ||
const result = await mainExecutionContext._adoptElementHandle(handle); | ||
await handle.dispose(); | ||
return result; | ||
} | ||
asElement() { | ||
@@ -320,0 +391,0 @@ return this; |
@@ -71,3 +71,3 @@ "use strict"; | ||
} | ||
if (!found && currentNode.matches(selector)) { | ||
if (currentNode !== root && !found && currentNode.matches(selector)) { | ||
found = currentNode; | ||
@@ -95,3 +95,3 @@ } | ||
} | ||
if (currentNode.matches(selector)) { | ||
if (currentNode !== root && currentNode.matches(selector)) { | ||
result.push(currentNode); | ||
@@ -98,0 +98,0 @@ } |
@@ -19,3 +19,3 @@ /** | ||
import { CDPSession } from './Connection.js'; | ||
import { Browser, BrowserContext } from './Browser.js'; | ||
import { Browser, BrowserContext, IsPageTargetCallback } from './Browser.js'; | ||
import { Viewport } from './PuppeteerViewport.js'; | ||
@@ -63,4 +63,8 @@ import { Protocol } from 'devtools-protocol'; | ||
*/ | ||
constructor(targetInfo: Protocol.Target.TargetInfo, browserContext: BrowserContext, sessionFactory: () => Promise<CDPSession>, ignoreHTTPSErrors: boolean, defaultViewport: Viewport | null, screenshotTaskQueue: TaskQueue); | ||
_isPageTargetCallback: IsPageTargetCallback; | ||
/** | ||
* @internal | ||
*/ | ||
constructor(targetInfo: Protocol.Target.TargetInfo, browserContext: BrowserContext, sessionFactory: () => Promise<CDPSession>, ignoreHTTPSErrors: boolean, defaultViewport: Viewport | null, screenshotTaskQueue: TaskQueue, isPageTargetCallback: IsPageTargetCallback); | ||
/** | ||
* Creates a Chrome Devtools Protocol session attached to the target. | ||
@@ -67,0 +71,0 @@ */ |
@@ -28,3 +28,3 @@ "use strict"; | ||
*/ | ||
constructor(targetInfo, browserContext, sessionFactory, ignoreHTTPSErrors, defaultViewport, screenshotTaskQueue) { | ||
constructor(targetInfo, browserContext, sessionFactory, ignoreHTTPSErrors, defaultViewport, screenshotTaskQueue, isPageTargetCallback) { | ||
this._targetInfo = targetInfo; | ||
@@ -37,2 +37,3 @@ this._browserContext = browserContext; | ||
this._screenshotTaskQueue = screenshotTaskQueue; | ||
this._isPageTargetCallback = isPageTargetCallback; | ||
/** @type {?Promise<!Puppeteer.Page>} */ | ||
@@ -57,3 +58,4 @@ this._pagePromise = null; | ||
this._isInitialized = | ||
this._targetInfo.type !== 'page' || this._targetInfo.url !== ''; | ||
!this._isPageTargetCallback(this._targetInfo) || | ||
this._targetInfo.url !== ''; | ||
if (this._isInitialized) | ||
@@ -72,6 +74,3 @@ this._initializedCallback(true); | ||
async page() { | ||
if ((this._targetInfo.type === 'page' || | ||
this._targetInfo.type === 'background_page' || | ||
this._targetInfo.type === 'webview') && | ||
!this._pagePromise) { | ||
if (this._isPageTargetCallback(this._targetInfo) && !this._pagePromise) { | ||
this._pagePromise = this._sessionFactory().then((client) => Page_js_1.Page.create(client, this, this._ignoreHTTPSErrors, this._defaultViewport, this._screenshotTaskQueue)); | ||
@@ -142,3 +141,4 @@ } | ||
if (!this._isInitialized && | ||
(this._targetInfo.type !== 'page' || this._targetInfo.url !== '')) { | ||
(!this._isPageTargetCallback(this._targetInfo) || | ||
this._targetInfo.url !== '')) { | ||
this._isInitialized = true; | ||
@@ -145,0 +145,0 @@ this._initializedCallback(true); |
@@ -1,2 +0,2 @@ | ||
export declare const packageVersion = "13.7.0"; | ||
export declare const packageVersion = "14.1.0"; | ||
//# sourceMappingURL=version.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.packageVersion = void 0; | ||
exports.packageVersion = '13.7.0'; | ||
exports.packageVersion = '14.1.0'; | ||
//# sourceMappingURL=version.js.map |
@@ -159,3 +159,5 @@ "use strict"; | ||
'--disable-extensions', | ||
'--disable-features=Translate,BackForwardCache', | ||
// TODO: remove AvoidUnnecessaryBeforeUnloadCheckSync below | ||
// once crbug.com/1324138 is fixed and released. | ||
'--disable-features=Translate,BackForwardCache,AvoidUnnecessaryBeforeUnloadCheckSync', | ||
'--disable-hang-monitor', | ||
@@ -162,0 +164,0 @@ '--disable-ipc-flooding-protection', |
@@ -49,2 +49,6 @@ /** | ||
/** | ||
* @internal | ||
*/ | ||
export declare type IsPageTargetCallback = (target: Protocol.Target.TargetInfo) => boolean; | ||
/** | ||
* @public | ||
@@ -157,3 +161,3 @@ */ | ||
*/ | ||
static create(connection: Connection, contextIds: string[], ignoreHTTPSErrors: boolean, defaultViewport?: Viewport | null, process?: ChildProcess, closeCallback?: BrowserCloseCallback, targetFilterCallback?: TargetFilterCallback): Promise<Browser>; | ||
static create(connection: Connection, contextIds: string[], ignoreHTTPSErrors: boolean, defaultViewport?: Viewport | null, process?: ChildProcess, closeCallback?: BrowserCloseCallback, targetFilterCallback?: TargetFilterCallback, isPageTargetCallback?: IsPageTargetCallback): Promise<Browser>; | ||
private _ignoreHTTPSErrors; | ||
@@ -165,2 +169,3 @@ private _defaultViewport?; | ||
private _targetFilterCallback; | ||
private _isPageTargetCallback; | ||
private _defaultContext; | ||
@@ -178,3 +183,3 @@ private _contexts; | ||
*/ | ||
constructor(connection: Connection, contextIds: string[], ignoreHTTPSErrors: boolean, defaultViewport?: Viewport | null, process?: ChildProcess, closeCallback?: BrowserCloseCallback, targetFilterCallback?: TargetFilterCallback); | ||
constructor(connection: Connection, contextIds: string[], ignoreHTTPSErrors: boolean, defaultViewport?: Viewport | null, process?: ChildProcess, closeCallback?: BrowserCloseCallback, targetFilterCallback?: TargetFilterCallback, isPageTargetCallback?: IsPageTargetCallback); | ||
/** | ||
@@ -186,2 +191,6 @@ * The spawned browser process. Returns `null` if the browser instance was created with | ||
/** | ||
* @internal | ||
*/ | ||
_setIsPageTargetCallback(isPageTargetCallback?: IsPageTargetCallback): void; | ||
/** | ||
* Creates a new incognito browser context. This won't share cookies/cache with other | ||
@@ -188,0 +197,0 @@ * browser contexts. |
@@ -93,3 +93,3 @@ /** | ||
*/ | ||
constructor(connection, contextIds, ignoreHTTPSErrors, defaultViewport, process, closeCallback, targetFilterCallback) { | ||
constructor(connection, contextIds, ignoreHTTPSErrors, defaultViewport, process, closeCallback, targetFilterCallback, isPageTargetCallback) { | ||
super(); | ||
@@ -104,2 +104,3 @@ this._ignoredTargets = new Set(); | ||
this._targetFilterCallback = targetFilterCallback || (() => true); | ||
this._setIsPageTargetCallback(isPageTargetCallback); | ||
this._defaultContext = new BrowserContext(this._connection, this); | ||
@@ -118,4 +119,4 @@ this._contexts = new Map(); | ||
*/ | ||
static async create(connection, contextIds, ignoreHTTPSErrors, defaultViewport, process, closeCallback, targetFilterCallback) { | ||
const browser = new Browser(connection, contextIds, ignoreHTTPSErrors, defaultViewport, process, closeCallback, targetFilterCallback); | ||
static async create(connection, contextIds, ignoreHTTPSErrors, defaultViewport, process, closeCallback, targetFilterCallback, isPageTargetCallback) { | ||
const browser = new Browser(connection, contextIds, ignoreHTTPSErrors, defaultViewport, process, closeCallback, targetFilterCallback, isPageTargetCallback); | ||
await connection.send('Target.setDiscoverTargets', { discover: true }); | ||
@@ -133,2 +134,14 @@ return browser; | ||
/** | ||
* @internal | ||
*/ | ||
_setIsPageTargetCallback(isPageTargetCallback) { | ||
this._isPageTargetCallback = | ||
isPageTargetCallback || | ||
((target) => { | ||
return (target.type === 'page' || | ||
target.type === 'background_page' || | ||
target.type === 'webview'); | ||
}); | ||
} | ||
/** | ||
* Creates a new incognito browser context. This won't share cookies/cache with other | ||
@@ -201,3 +214,3 @@ * browser contexts. | ||
} | ||
const target = new Target(targetInfo, context, () => this._connection.createSession(targetInfo), this._ignoreHTTPSErrors, (_a = this._defaultViewport) !== null && _a !== void 0 ? _a : null, this._screenshotTaskQueue); | ||
const target = new Target(targetInfo, context, () => this._connection.createSession(targetInfo), this._ignoreHTTPSErrors, (_a = this._defaultViewport) !== null && _a !== void 0 ? _a : null, this._screenshotTaskQueue, this._isPageTargetCallback); | ||
assert(!this._targets.has(event.targetInfo.targetId), 'Target should not exist before targetCreated'); | ||
@@ -204,0 +217,0 @@ this._targets.set(event.targetInfo.targetId, target); |
@@ -17,3 +17,3 @@ /** | ||
import { ConnectionTransport } from './ConnectionTransport.js'; | ||
import { Browser, TargetFilterCallback } from './Browser.js'; | ||
import { Browser, TargetFilterCallback, IsPageTargetCallback } from './Browser.js'; | ||
import { Viewport } from './PuppeteerViewport.js'; | ||
@@ -44,2 +44,6 @@ /** | ||
targetFilter?: TargetFilterCallback; | ||
/** | ||
* @internal | ||
*/ | ||
isPageTarget?: IsPageTargetCallback; | ||
} | ||
@@ -46,0 +50,0 @@ /** |
@@ -16,3 +16,3 @@ /** | ||
*/ | ||
import { Browser } from './Browser.js'; | ||
import { Browser, } from './Browser.js'; | ||
import { assert } from './assert.js'; | ||
@@ -35,3 +35,3 @@ import { debugError } from '../common/helper.js'; | ||
export const connectToBrowser = async (options) => { | ||
const { browserWSEndpoint, browserURL, ignoreHTTPSErrors = false, defaultViewport = { width: 800, height: 600 }, transport, slowMo = 0, targetFilter, } = options; | ||
const { browserWSEndpoint, browserURL, ignoreHTTPSErrors = false, defaultViewport = { width: 800, height: 600 }, transport, slowMo = 0, targetFilter, isPageTarget, } = options; | ||
assert(Number(!!browserWSEndpoint) + Number(!!browserURL) + Number(!!transport) === | ||
@@ -55,3 +55,3 @@ 1, 'Exactly one of browserWSEndpoint, browserURL or transport must be passed to puppeteer.connect'); | ||
const { browserContextIds } = await connection.send('Target.getBrowserContexts'); | ||
return Browser.create(connection, browserContextIds, ignoreHTTPSErrors, defaultViewport, null, () => connection.send('Browser.close').catch(debugError), targetFilter); | ||
return Browser.create(connection, browserContextIds, ignoreHTTPSErrors, defaultViewport, null, () => connection.send('Browser.close').catch(debugError), targetFilter, isPageTarget); | ||
}; | ||
@@ -58,0 +58,0 @@ async function getWSEndpoint(browserURL) { |
@@ -268,2 +268,57 @@ /** | ||
}): Promise<ElementHandle | null>; | ||
/** | ||
* Wait for the `xpath` within the element. If at the moment of calling the | ||
* method the `xpath` already exists, the method will return immediately. If | ||
* the `xpath` doesn't appear after the `timeout` milliseconds of waiting, the | ||
* function will throw. | ||
* | ||
* If `xpath` starts with `//` instead of `.//`, the dot will be appended automatically. | ||
* | ||
* This method works across navigation | ||
* ```js | ||
* const puppeteer = require('puppeteer'); | ||
* (async () => { | ||
* const browser = await puppeteer.launch(); | ||
* const page = await browser.newPage(); | ||
* let currentURL; | ||
* page | ||
* .waitForXPath('//img') | ||
* .then(() => console.log('First URL with image: ' + currentURL)); | ||
* for (currentURL of [ | ||
* 'https://example.com', | ||
* 'https://google.com', | ||
* 'https://bbc.com', | ||
* ]) { | ||
* await page.goto(currentURL); | ||
* } | ||
* await browser.close(); | ||
* })(); | ||
* ``` | ||
* @param xpath - A | ||
* {@link https://developer.mozilla.org/en-US/docs/Web/XPath | xpath} of an | ||
* element to wait for | ||
* @param options - Optional waiting parameters | ||
* @returns Promise which resolves when element specified by xpath string is | ||
* added to DOM. Resolves to `null` if waiting for `hidden: true` and xpath is | ||
* not found in DOM. | ||
* @remarks | ||
* The optional Argument `options` have properties: | ||
* | ||
* - `visible`: A boolean to wait for element to be present in DOM and to be | ||
* visible, i.e. to not have `display: none` or `visibility: hidden` CSS | ||
* properties. Defaults to `false`. | ||
* | ||
* - `hidden`: A boolean wait for element to not be found in the DOM or to be | ||
* hidden, i.e. have `display: none` or `visibility: hidden` CSS properties. | ||
* Defaults to `false`. | ||
* | ||
* - `timeout`: A number which is maximum time to wait for in milliseconds. | ||
* Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default | ||
* value can be changed by using the {@link Page.setDefaultTimeout} method. | ||
*/ | ||
waitForXPath(xpath: string, options?: { | ||
visible?: boolean; | ||
hidden?: boolean; | ||
timeout?: number; | ||
}): Promise<ElementHandle | null>; | ||
asElement(): ElementHandle<ElementType> | null; | ||
@@ -270,0 +325,0 @@ /** |
@@ -290,2 +290,73 @@ /** | ||
} | ||
/** | ||
* Wait for the `xpath` within the element. If at the moment of calling the | ||
* method the `xpath` already exists, the method will return immediately. If | ||
* the `xpath` doesn't appear after the `timeout` milliseconds of waiting, the | ||
* function will throw. | ||
* | ||
* If `xpath` starts with `//` instead of `.//`, the dot will be appended automatically. | ||
* | ||
* This method works across navigation | ||
* ```js | ||
* const puppeteer = require('puppeteer'); | ||
* (async () => { | ||
* const browser = await puppeteer.launch(); | ||
* const page = await browser.newPage(); | ||
* let currentURL; | ||
* page | ||
* .waitForXPath('//img') | ||
* .then(() => console.log('First URL with image: ' + currentURL)); | ||
* for (currentURL of [ | ||
* 'https://example.com', | ||
* 'https://google.com', | ||
* 'https://bbc.com', | ||
* ]) { | ||
* await page.goto(currentURL); | ||
* } | ||
* await browser.close(); | ||
* })(); | ||
* ``` | ||
* @param xpath - A | ||
* {@link https://developer.mozilla.org/en-US/docs/Web/XPath | xpath} of an | ||
* element to wait for | ||
* @param options - Optional waiting parameters | ||
* @returns Promise which resolves when element specified by xpath string is | ||
* added to DOM. Resolves to `null` if waiting for `hidden: true` and xpath is | ||
* not found in DOM. | ||
* @remarks | ||
* The optional Argument `options` have properties: | ||
* | ||
* - `visible`: A boolean to wait for element to be present in DOM and to be | ||
* visible, i.e. to not have `display: none` or `visibility: hidden` CSS | ||
* properties. Defaults to `false`. | ||
* | ||
* - `hidden`: A boolean wait for element to not be found in the DOM or to be | ||
* hidden, i.e. have `display: none` or `visibility: hidden` CSS properties. | ||
* Defaults to `false`. | ||
* | ||
* - `timeout`: A number which is maximum time to wait for in milliseconds. | ||
* Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default | ||
* value can be changed by using the {@link Page.setDefaultTimeout} method. | ||
*/ | ||
async waitForXPath(xpath, options = {}) { | ||
const frame = this._context.frame(); | ||
const secondaryContext = await frame._secondaryWorld.executionContext(); | ||
const adoptedRoot = await secondaryContext._adoptElementHandle(this); | ||
xpath = xpath.startsWith('//') ? '.' + xpath : xpath; | ||
if (!xpath.startsWith('.//')) { | ||
await adoptedRoot.dispose(); | ||
throw new Error('Unsupported xpath expression: ' + xpath); | ||
} | ||
const handle = await frame._secondaryWorld.waitForXPath(xpath, { | ||
...options, | ||
root: adoptedRoot, | ||
}); | ||
await adoptedRoot.dispose(); | ||
if (!handle) | ||
return null; | ||
const mainExecutionContext = await frame._mainWorld.executionContext(); | ||
const result = await mainExecutionContext._adoptElementHandle(handle); | ||
await handle.dispose(); | ||
return result; | ||
} | ||
asElement() { | ||
@@ -292,0 +363,0 @@ return this; |
@@ -68,3 +68,3 @@ /** | ||
} | ||
if (!found && currentNode.matches(selector)) { | ||
if (currentNode !== root && !found && currentNode.matches(selector)) { | ||
found = currentNode; | ||
@@ -92,3 +92,3 @@ } | ||
} | ||
if (currentNode.matches(selector)) { | ||
if (currentNode !== root && currentNode.matches(selector)) { | ||
result.push(currentNode); | ||
@@ -95,0 +95,0 @@ } |
@@ -19,3 +19,3 @@ /** | ||
import { CDPSession } from './Connection.js'; | ||
import { Browser, BrowserContext } from './Browser.js'; | ||
import { Browser, BrowserContext, IsPageTargetCallback } from './Browser.js'; | ||
import { Viewport } from './PuppeteerViewport.js'; | ||
@@ -63,4 +63,8 @@ import { Protocol } from 'devtools-protocol'; | ||
*/ | ||
constructor(targetInfo: Protocol.Target.TargetInfo, browserContext: BrowserContext, sessionFactory: () => Promise<CDPSession>, ignoreHTTPSErrors: boolean, defaultViewport: Viewport | null, screenshotTaskQueue: TaskQueue); | ||
_isPageTargetCallback: IsPageTargetCallback; | ||
/** | ||
* @internal | ||
*/ | ||
constructor(targetInfo: Protocol.Target.TargetInfo, browserContext: BrowserContext, sessionFactory: () => Promise<CDPSession>, ignoreHTTPSErrors: boolean, defaultViewport: Viewport | null, screenshotTaskQueue: TaskQueue, isPageTargetCallback: IsPageTargetCallback); | ||
/** | ||
* Creates a Chrome Devtools Protocol session attached to the target. | ||
@@ -67,0 +71,0 @@ */ |
@@ -25,3 +25,3 @@ /** | ||
*/ | ||
constructor(targetInfo, browserContext, sessionFactory, ignoreHTTPSErrors, defaultViewport, screenshotTaskQueue) { | ||
constructor(targetInfo, browserContext, sessionFactory, ignoreHTTPSErrors, defaultViewport, screenshotTaskQueue, isPageTargetCallback) { | ||
this._targetInfo = targetInfo; | ||
@@ -34,2 +34,3 @@ this._browserContext = browserContext; | ||
this._screenshotTaskQueue = screenshotTaskQueue; | ||
this._isPageTargetCallback = isPageTargetCallback; | ||
/** @type {?Promise<!Puppeteer.Page>} */ | ||
@@ -54,3 +55,4 @@ this._pagePromise = null; | ||
this._isInitialized = | ||
this._targetInfo.type !== 'page' || this._targetInfo.url !== ''; | ||
!this._isPageTargetCallback(this._targetInfo) || | ||
this._targetInfo.url !== ''; | ||
if (this._isInitialized) | ||
@@ -69,6 +71,3 @@ this._initializedCallback(true); | ||
async page() { | ||
if ((this._targetInfo.type === 'page' || | ||
this._targetInfo.type === 'background_page' || | ||
this._targetInfo.type === 'webview') && | ||
!this._pagePromise) { | ||
if (this._isPageTargetCallback(this._targetInfo) && !this._pagePromise) { | ||
this._pagePromise = this._sessionFactory().then((client) => Page.create(client, this, this._ignoreHTTPSErrors, this._defaultViewport, this._screenshotTaskQueue)); | ||
@@ -139,3 +138,4 @@ } | ||
if (!this._isInitialized && | ||
(this._targetInfo.type !== 'page' || this._targetInfo.url !== '')) { | ||
(!this._isPageTargetCallback(this._targetInfo) || | ||
this._targetInfo.url !== '')) { | ||
this._isInitialized = true; | ||
@@ -142,0 +142,0 @@ this._initializedCallback(true); |
@@ -1,2 +0,2 @@ | ||
export declare const packageVersion = "13.7.0"; | ||
export declare const packageVersion = "14.1.0"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -1,2 +0,2 @@ | ||
export const packageVersion = '13.7.0'; | ||
export const packageVersion = '14.1.0'; | ||
//# sourceMappingURL=version.js.map |
@@ -134,3 +134,5 @@ /** | ||
'--disable-extensions', | ||
'--disable-features=Translate,BackForwardCache', | ||
// TODO: remove AvoidUnnecessaryBeforeUnloadCheckSync below | ||
// once crbug.com/1324138 is fixed and released. | ||
'--disable-features=Translate,BackForwardCache,AvoidUnnecessaryBeforeUnloadCheckSync', | ||
'--disable-hang-monitor', | ||
@@ -137,0 +139,0 @@ '--disable-ipc-flooding-protection', |
{ | ||
"name": "puppeteer-core", | ||
"version": "14.0.0", | ||
"version": "14.1.0", | ||
"description": "A high-level API to control headless Chrome over the DevTools Protocol", | ||
@@ -111,3 +111,3 @@ "keywords": [ | ||
"@types/ws": "8.5.3", | ||
"@typescript-eslint/eslint-plugin": "5.22.0", | ||
"@typescript-eslint/eslint-plugin": "5.23.0", | ||
"@typescript-eslint/parser": "5.22.0", | ||
@@ -117,3 +117,3 @@ "@web/test-runner": "0.13.27", | ||
"cross-env": "7.0.3", | ||
"eslint": "8.14.0", | ||
"eslint": "8.15.0", | ||
"eslint-config-prettier": "8.5.0", | ||
@@ -120,0 +120,0 @@ "eslint-plugin-import": "2.26.0", |
@@ -11,3 +11,3 @@ # Puppeteer | ||
###### [API](https://github.com/puppeteer/puppeteer/blob/v14.0.0/docs/api.md) | [FAQ](#faq) | [Contributing](https://github.com/puppeteer/puppeteer/blob/main/CONTRIBUTING.md) | [Troubleshooting](https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md) | ||
###### [API](https://github.com/puppeteer/puppeteer/blob/v14.1.0/docs/api.md) | [FAQ](#faq) | [Contributing](https://github.com/puppeteer/puppeteer/blob/main/CONTRIBUTING.md) | [Troubleshooting](https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md) | ||
@@ -43,3 +43,3 @@ > Puppeteer is a Node library which provides a high-level API to control Chrome or Chromium over the [DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/). Puppeteer runs [headless](https://developers.google.com/web/updates/2017/04/headless-chrome) by default, but can be configured to run full (non-headless) Chrome or Chromium. | ||
Note: When you install Puppeteer, it downloads a recent version of Chromium (~170MB Mac, ~282MB Linux, ~280MB Win) that is guaranteed to work with the API. To skip the download, download into another path, or download a different browser, see [Environment variables](https://github.com/puppeteer/puppeteer/blob/v14.0.0/docs/api.md#environment-variables). | ||
Note: When you install Puppeteer, it downloads a recent version of Chromium (~170MB Mac, ~282MB Linux, ~280MB Win) that is guaranteed to work with the API. To skip the download, download into another path, or download a different browser, see [Environment variables](https://github.com/puppeteer/puppeteer/blob/v14.1.0/docs/api.md#environment-variables). | ||
@@ -68,3 +68,3 @@ ### puppeteer-core | ||
Puppeteer will be familiar to people using other browser testing frameworks. You create an instance | ||
of `Browser`, open pages, and then manipulate them with [Puppeteer's API](https://github.com/puppeteer/puppeteer/blob/v14.0.0/docs/api.md#). | ||
of `Browser`, open pages, and then manipulate them with [Puppeteer's API](https://github.com/puppeteer/puppeteer/blob/v14.1.0/docs/api.md#). | ||
@@ -94,3 +94,3 @@ **Example** - navigating to https://example.com and saving a screenshot as _example.png_: | ||
Puppeteer sets an initial page size to 800×600px, which defines the screenshot size. The page size can be customized with [`Page.setViewport()`](https://github.com/puppeteer/puppeteer/blob/v14.0.0/docs/api.md#pagesetviewportviewport). | ||
Puppeteer sets an initial page size to 800×600px, which defines the screenshot size. The page size can be customized with [`Page.setViewport()`](https://github.com/puppeteer/puppeteer/blob/v14.1.0/docs/api.md#pagesetviewportviewport). | ||
@@ -122,3 +122,3 @@ **Example** - create a PDF. | ||
See [`Page.pdf()`](https://github.com/puppeteer/puppeteer/blob/v14.0.0/docs/api.md#pagepdfoptions) for more information about creating pdfs. | ||
See [`Page.pdf()`](https://github.com/puppeteer/puppeteer/blob/v14.1.0/docs/api.md#pagepdfoptions) for more information about creating pdfs. | ||
@@ -158,3 +158,3 @@ **Example** - evaluate script in the context of the page | ||
See [`Page.evaluate()`](https://github.com/puppeteer/puppeteer/blob/v14.0.0/docs/api.md#pageevaluatepagefunction-args) for more information on `evaluate` and related methods like `evaluateOnNewDocument` and `exposeFunction`. | ||
See [`Page.evaluate()`](https://github.com/puppeteer/puppeteer/blob/v14.1.0/docs/api.md#pageevaluatepagefunction-args) for more information on `evaluate` and related methods like `evaluateOnNewDocument` and `exposeFunction`. | ||
@@ -169,3 +169,3 @@ <!-- [END getstarted] --> | ||
Puppeteer launches Chromium in [headless mode](https://developers.google.com/web/updates/2017/04/headless-chrome). To launch a full version of Chromium, set the [`headless` option](https://github.com/puppeteer/puppeteer/blob/v14.0.0/docs/api.md#puppeteerlaunchoptions) when launching a browser: | ||
Puppeteer launches Chromium in [headless mode](https://developers.google.com/web/updates/2017/04/headless-chrome). To launch a full version of Chromium, set the [`headless` option](https://github.com/puppeteer/puppeteer/blob/v14.1.0/docs/api.md#puppeteerlaunchoptions) when launching a browser: | ||
@@ -186,3 +186,3 @@ ```js | ||
You can also use Puppeteer with Firefox Nightly (experimental support). See [`Puppeteer.launch()`](https://github.com/puppeteer/puppeteer/blob/v14.0.0/docs/api.md#puppeteerlaunchoptions) for more information. | ||
You can also use Puppeteer with Firefox Nightly (experimental support). See [`Puppeteer.launch()`](https://github.com/puppeteer/puppeteer/blob/v14.1.0/docs/api.md#puppeteerlaunchoptions) for more information. | ||
@@ -199,3 +199,3 @@ See [`this article`](https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/) for a description of the differences between Chromium and Chrome. [`This article`](https://chromium.googlesource.com/chromium/src/+/refs/heads/main/docs/chromium_browser_vs_google_chrome.md) describes some differences for Linux users. | ||
- [API Documentation](https://github.com/puppeteer/puppeteer/blob/v14.0.0/docs/api.md) | ||
- [API Documentation](https://github.com/puppeteer/puppeteer/blob/v14.1.0/docs/api.md) | ||
- [Examples](https://github.com/puppeteer/puppeteer/tree/main/examples/) | ||
@@ -342,3 +342,3 @@ - [Community list of Puppeteer resources](https://github.com/transitive-bullshit/awesome-puppeteer) | ||
From Puppeteer v2.1.0 onwards you can specify [`puppeteer.launch({product: 'firefox'})`](https://github.com/puppeteer/puppeteer/blob/v14.0.0/docs/api.md#puppeteerlaunchoptions) to run your Puppeteer scripts in Firefox Nightly, without any additional custom patches. While [an older experiment](https://www.npmjs.com/package/puppeteer-firefox) required a patched version of Firefox, [the current approach](https://wiki.mozilla.org/Remote) works with “stock” Firefox. | ||
From Puppeteer v2.1.0 onwards you can specify [`puppeteer.launch({product: 'firefox'})`](https://github.com/puppeteer/puppeteer/blob/v14.1.0/docs/api.md#puppeteerlaunchoptions) to run your Puppeteer scripts in Firefox Nightly, without any additional custom patches. While [an older experiment](https://www.npmjs.com/package/puppeteer-firefox) required a patched version of Firefox, [the current approach](https://wiki.mozilla.org/Remote) works with “stock” Firefox. | ||
@@ -446,3 +446,3 @@ We will continue to collaborate with other browser vendors to bring Puppeteer support to browsers such as Safari. | ||
- Puppeteer is bundled with Chromium — not Chrome — and so by default, it inherits all of [Chromium's media-related limitations](https://www.chromium.org/audio-video). This means that Puppeteer does not support licensed formats such as AAC or H.264. (However, it is possible to force Puppeteer to use a separately-installed version Chrome instead of Chromium via the [`executablePath` option to `puppeteer.launch`](https://github.com/puppeteer/puppeteer/blob/v14.0.0/docs/api.md#puppeteerlaunchoptions). You should only use this configuration if you need an official release of Chrome that supports these media formats.) | ||
- Puppeteer is bundled with Chromium — not Chrome — and so by default, it inherits all of [Chromium's media-related limitations](https://www.chromium.org/audio-video). This means that Puppeteer does not support licensed formats such as AAC or H.264. (However, it is possible to force Puppeteer to use a separately-installed version Chrome instead of Chromium via the [`executablePath` option to `puppeteer.launch`](https://github.com/puppeteer/puppeteer/blob/v14.1.0/docs/api.md#puppeteerlaunchoptions). You should only use this configuration if you need an official release of Chrome that supports these media formats.) | ||
- Since Puppeteer (in all configurations) controls a desktop version of Chromium/Chrome, features that are only supported by the mobile version of Chrome are not supported. This means that Puppeteer [does not support HTTP Live Streaming (HLS)](https://caniuse.com/#feat=http-live-streaming). | ||
@@ -449,0 +449,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3010373
54939