mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
feat: enable tab targets (#11099)
This commit is contained in:
parent
9ce204e27e
commit
8324c16348
5
.github/workflows/ci.yml
vendored
5
.github/workflows/ci.yml
vendored
@ -150,7 +150,6 @@ jobs:
|
|||||||
- chrome-headful
|
- chrome-headful
|
||||||
- chrome-new-headless
|
- chrome-new-headless
|
||||||
- chrome-bidi
|
- chrome-bidi
|
||||||
- chrome-new-headless-tab
|
|
||||||
shard:
|
shard:
|
||||||
- 1/2
|
- 1/2
|
||||||
- 2/2
|
- 2/2
|
||||||
@ -159,10 +158,6 @@ jobs:
|
|||||||
suite: chrome-bidi
|
suite: chrome-bidi
|
||||||
- os: macos-latest
|
- os: macos-latest
|
||||||
suite: chrome-headful
|
suite: chrome-headful
|
||||||
- os: windows-latest
|
|
||||||
suite: chrome-new-headless-tab
|
|
||||||
- os: macos-latest
|
|
||||||
suite: chrome-new-headless-tab
|
|
||||||
steps:
|
steps:
|
||||||
- name: Check out repository
|
- name: Check out repository
|
||||||
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
|
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
"test-types": "tsd -t packages/puppeteer",
|
"test-types": "tsd -t packages/puppeteer",
|
||||||
"test:chrome:headful": "wireit",
|
"test:chrome:headful": "wireit",
|
||||||
"test:chrome:new-headless": "wireit",
|
"test:chrome:new-headless": "wireit",
|
||||||
"test:chrome:new-headless-tab": "wireit",
|
|
||||||
"test:chrome:headless": "wireit",
|
"test:chrome:headless": "wireit",
|
||||||
"test:chrome:bidi": "wireit",
|
"test:chrome:bidi": "wireit",
|
||||||
"test:chrome:bidi-local": "wireit",
|
"test:chrome:bidi-local": "wireit",
|
||||||
@ -76,9 +75,6 @@
|
|||||||
"test:chrome:new-headless": {
|
"test:chrome:new-headless": {
|
||||||
"command": "npm test -- --test-suite chrome-new-headless"
|
"command": "npm test -- --test-suite chrome-new-headless"
|
||||||
},
|
},
|
||||||
"test:chrome:new-headless-tab": {
|
|
||||||
"command": "npm test -- --test-suite chrome-new-headless-tab"
|
|
||||||
},
|
|
||||||
"test:chrome:bidi": {
|
"test:chrome:bidi": {
|
||||||
"command": "npm test -- --test-suite chrome-bidi"
|
"command": "npm test -- --test-suite chrome-bidi"
|
||||||
},
|
},
|
||||||
|
@ -16,6 +16,6 @@
|
|||||||
|
|
||||||
export const testChromeBuildId = '113.0.5672.0';
|
export const testChromeBuildId = '113.0.5672.0';
|
||||||
export const testChromiumBuildId = '1083080';
|
export const testChromiumBuildId = '1083080';
|
||||||
export const testFirefoxBuildId = '119.0a1';
|
export const testFirefoxBuildId = '120.0a1';
|
||||||
export const testChromeDriverBuildId = '115.0.5763.0';
|
export const testChromeDriverBuildId = '115.0.5763.0';
|
||||||
export const testChromeHeadlessShellBuildId = '118.0.5950.0';
|
export const testChromeHeadlessShellBuildId = '118.0.5950.0';
|
||||||
|
@ -33,7 +33,6 @@ import {CDPSessionEvent, type CDPSession} from '../api/CDPSession.js';
|
|||||||
import type {Page} from '../api/Page.js';
|
import type {Page} from '../api/Page.js';
|
||||||
import type {Target} from '../api/Target.js';
|
import type {Target} from '../api/Target.js';
|
||||||
import type {Viewport} from '../common/Viewport.js';
|
import type {Viewport} from '../common/Viewport.js';
|
||||||
import {USE_TAB_TARGET} from '../environment.js';
|
|
||||||
import {assert} from '../util/assert.js';
|
import {assert} from '../util/assert.js';
|
||||||
|
|
||||||
import {ChromeTargetManager} from './ChromeTargetManager.js';
|
import {ChromeTargetManager} from './ChromeTargetManager.js';
|
||||||
@ -63,8 +62,7 @@ export class CdpBrowser extends BrowserBase {
|
|||||||
closeCallback?: BrowserCloseCallback,
|
closeCallback?: BrowserCloseCallback,
|
||||||
targetFilterCallback?: TargetFilterCallback,
|
targetFilterCallback?: TargetFilterCallback,
|
||||||
isPageTargetCallback?: IsPageTargetCallback,
|
isPageTargetCallback?: IsPageTargetCallback,
|
||||||
waitForInitiallyDiscoveredTargets = true,
|
waitForInitiallyDiscoveredTargets = true
|
||||||
useTabTarget = USE_TAB_TARGET
|
|
||||||
): Promise<CdpBrowser> {
|
): Promise<CdpBrowser> {
|
||||||
const browser = new CdpBrowser(
|
const browser = new CdpBrowser(
|
||||||
product,
|
product,
|
||||||
@ -76,8 +74,7 @@ export class CdpBrowser extends BrowserBase {
|
|||||||
closeCallback,
|
closeCallback,
|
||||||
targetFilterCallback,
|
targetFilterCallback,
|
||||||
isPageTargetCallback,
|
isPageTargetCallback,
|
||||||
waitForInitiallyDiscoveredTargets,
|
waitForInitiallyDiscoveredTargets
|
||||||
useTabTarget
|
|
||||||
);
|
);
|
||||||
await browser._attach();
|
await browser._attach();
|
||||||
return browser;
|
return browser;
|
||||||
@ -107,8 +104,7 @@ export class CdpBrowser extends BrowserBase {
|
|||||||
closeCallback?: BrowserCloseCallback,
|
closeCallback?: BrowserCloseCallback,
|
||||||
targetFilterCallback?: TargetFilterCallback,
|
targetFilterCallback?: TargetFilterCallback,
|
||||||
isPageTargetCallback?: IsPageTargetCallback,
|
isPageTargetCallback?: IsPageTargetCallback,
|
||||||
waitForInitiallyDiscoveredTargets = true,
|
waitForInitiallyDiscoveredTargets = true
|
||||||
useTabTarget = USE_TAB_TARGET
|
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
product = product || 'chrome';
|
product = product || 'chrome';
|
||||||
@ -134,8 +130,7 @@ export class CdpBrowser extends BrowserBase {
|
|||||||
connection,
|
connection,
|
||||||
this.#createTarget,
|
this.#createTarget,
|
||||||
this.#targetFilterCallback,
|
this.#targetFilterCallback,
|
||||||
waitForInitiallyDiscoveredTargets,
|
waitForInitiallyDiscoveredTargets
|
||||||
useTabTarget
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
this.#defaultContext = new CdpBrowserContext(this.#connection, this);
|
this.#defaultContext = new CdpBrowserContext(this.#connection, this);
|
||||||
|
@ -98,22 +98,15 @@ export class ChromeTargetManager
|
|||||||
#targetsIdsForInit = new Set<string>();
|
#targetsIdsForInit = new Set<string>();
|
||||||
#waitForInitiallyDiscoveredTargets = true;
|
#waitForInitiallyDiscoveredTargets = true;
|
||||||
|
|
||||||
// TODO: remove the flag once the testing/rollout is done.
|
#discoveryFilter: Protocol.Target.FilterEntry[] = [{}];
|
||||||
#tabMode: boolean;
|
|
||||||
#discoveryFilter: Protocol.Target.FilterEntry[];
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
connection: Connection,
|
connection: Connection,
|
||||||
targetFactory: TargetFactory,
|
targetFactory: TargetFactory,
|
||||||
targetFilterCallback?: TargetFilterCallback,
|
targetFilterCallback?: TargetFilterCallback,
|
||||||
waitForInitiallyDiscoveredTargets = true,
|
waitForInitiallyDiscoveredTargets = true
|
||||||
useTabTarget = false
|
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
this.#tabMode = useTabTarget;
|
|
||||||
this.#discoveryFilter = this.#tabMode
|
|
||||||
? [{}]
|
|
||||||
: [{type: 'tab', exclude: true}, {}];
|
|
||||||
this.#connection = connection;
|
this.#connection = connection;
|
||||||
this.#targetFilterCallback = targetFilterCallback;
|
this.#targetFilterCallback = targetFilterCallback;
|
||||||
this.#targetFactory = targetFactory;
|
this.#targetFactory = targetFactory;
|
||||||
@ -166,15 +159,13 @@ export class ChromeTargetManager
|
|||||||
waitForDebuggerOnStart: true,
|
waitForDebuggerOnStart: true,
|
||||||
flatten: true,
|
flatten: true,
|
||||||
autoAttach: true,
|
autoAttach: true,
|
||||||
filter: this.#tabMode
|
filter: [
|
||||||
? [
|
{
|
||||||
{
|
type: 'page',
|
||||||
type: 'page',
|
exclude: true,
|
||||||
exclude: true,
|
},
|
||||||
},
|
...this.#discoveryFilter,
|
||||||
...this.#discoveryFilter,
|
],
|
||||||
]
|
|
||||||
: this.#discoveryFilter,
|
|
||||||
});
|
});
|
||||||
this.#finishInitializationIfReady();
|
this.#finishInitializationIfReady();
|
||||||
await this.#initializeDeferred.valueOrThrow();
|
await this.#initializeDeferred.valueOrThrow();
|
||||||
|
@ -27,13 +27,3 @@ export const DEFERRED_PROMISE_DEBUG_TIMEOUT =
|
|||||||
typeof process.env['PUPPETEER_DEFERRED_PROMISE_DEBUG_TIMEOUT'] !== 'undefined'
|
typeof process.env['PUPPETEER_DEFERRED_PROMISE_DEBUG_TIMEOUT'] !== 'undefined'
|
||||||
? Number(process.env['PUPPETEER_DEFERRED_PROMISE_DEBUG_TIMEOUT'])
|
? Number(process.env['PUPPETEER_DEFERRED_PROMISE_DEBUG_TIMEOUT'])
|
||||||
: -1;
|
: -1;
|
||||||
|
|
||||||
/**
|
|
||||||
* Only used for internal testing.
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
export const USE_TAB_TARGET =
|
|
||||||
typeof process !== 'undefined'
|
|
||||||
? process.env['PUPPETEER_INTERNAL_TAB_TARGET'] === 'true'
|
|
||||||
: false;
|
|
||||||
|
@ -25,7 +25,6 @@ import {
|
|||||||
|
|
||||||
import type {Browser} from '../api/Browser.js';
|
import type {Browser} from '../api/Browser.js';
|
||||||
import {debugError} from '../common/util.js';
|
import {debugError} from '../common/util.js';
|
||||||
import {USE_TAB_TARGET} from '../environment.js';
|
|
||||||
import {assert} from '../util/assert.js';
|
import {assert} from '../util/assert.js';
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
@ -175,10 +174,6 @@ export class ChromeLauncher extends ProductLauncher {
|
|||||||
'OptimizationHints',
|
'OptimizationHints',
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!USE_TAB_TARGET) {
|
|
||||||
disabledFeatures.push('Prerender2');
|
|
||||||
}
|
|
||||||
|
|
||||||
const chromeArguments = [
|
const chromeArguments = [
|
||||||
'--allow-pre-commit-input',
|
'--allow-pre-commit-input',
|
||||||
'--disable-background-networking',
|
'--disable-background-networking',
|
||||||
|
@ -18,12 +18,6 @@
|
|||||||
"parameters": ["chrome", "new-headless", "cdp"],
|
"parameters": ["chrome", "new-headless", "cdp"],
|
||||||
"expectedLineCoverage": 93
|
"expectedLineCoverage": 93
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"id": "chrome-new-headless-tab",
|
|
||||||
"platforms": ["linux"],
|
|
||||||
"parameters": ["chrome", "new-headless", "cdp", "tabTarget"],
|
|
||||||
"expectedLineCoverage": 93
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"id": "firefox-headless",
|
"id": "firefox-headless",
|
||||||
"platforms": ["linux", "darwin"],
|
"platforms": ["linux", "darwin"],
|
||||||
@ -69,9 +63,6 @@
|
|||||||
"webDriverBiDi": {
|
"webDriverBiDi": {
|
||||||
"PUPPETEER_PROTOCOL": "webDriverBiDi"
|
"PUPPETEER_PROTOCOL": "webDriverBiDi"
|
||||||
},
|
},
|
||||||
"cdp": {},
|
"cdp": {}
|
||||||
"tabTarget": {
|
|
||||||
"PUPPETEER_INTERNAL_TAB_TARGET": "true"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user