chore: allow enabling the tab target for testing (#10790)

This commit is contained in:
Alex Rudenko 2023-08-28 10:53:22 +02:00 committed by GitHub
parent ad0c793662
commit 6f1dd09cca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 9 deletions

View File

@ -128,11 +128,16 @@ jobs:
- chrome-headful - chrome-headful
- chrome-new-headless - chrome-new-headless
- chrome-bidi - chrome-bidi
- chrome-new-headless-tab
exclude: exclude:
- os: windows-latest - os: windows-latest
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@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0

View File

@ -32,6 +32,7 @@ import {
import {BrowserContext} from '../api/BrowserContext.js'; import {BrowserContext} from '../api/BrowserContext.js';
import {Page} from '../api/Page.js'; import {Page} from '../api/Page.js';
import {Target} from '../api/Target.js'; import {Target} from '../api/Target.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';
@ -65,7 +66,8 @@ 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,
@ -77,7 +79,8 @@ export class CDPBrowser extends BrowserBase {
closeCallback, closeCallback,
targetFilterCallback, targetFilterCallback,
isPageTargetCallback, isPageTargetCallback,
waitForInitiallyDiscoveredTargets waitForInitiallyDiscoveredTargets,
useTabTarget
); );
await browser._attach(); await browser._attach();
return browser; return browser;
@ -114,7 +117,8 @@ 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';
@ -141,7 +145,8 @@ 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);

View File

@ -99,16 +99,21 @@ export class ChromeTargetManager extends EventEmitter implements TargetManager {
#waitForInitiallyDiscoveredTargets = true; #waitForInitiallyDiscoveredTargets = true;
// TODO: remove the flag once the testing/rollout is done. // TODO: remove the flag once the testing/rollout is done.
#tabMode = false; #tabMode: boolean;
#discoveryFilter = this.#tabMode ? [{}] : [{type: 'tab', exclude: true}, {}]; #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;

View File

@ -27,3 +27,13 @@ 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;

View File

@ -25,6 +25,7 @@ import {
import {Browser} from '../api/Browser.js'; import {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 { import {
@ -178,7 +179,8 @@ export class ChromeLauncher extends ProductLauncher {
'--disable-dev-shm-usage', '--disable-dev-shm-usage',
'--disable-extensions', '--disable-extensions',
// AcceptCHFrame disabled because of crbug.com/1348106. // AcceptCHFrame disabled because of crbug.com/1348106.
'--disable-features=Translate,BackForwardCache,AcceptCHFrame,MediaRouter,OptimizationHints,Prerender2', '--disable-features=Translate,BackForwardCache,AcceptCHFrame,MediaRouter,OptimizationHints',
...(USE_TAB_TARGET ? [] : ['--disable-features=Prerender2']),
'--disable-hang-monitor', '--disable-hang-monitor',
'--disable-ipc-flooding-protection', '--disable-ipc-flooding-protection',
'--disable-popup-blocking', '--disable-popup-blocking',

View File

@ -18,6 +18,12 @@
"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"],
@ -63,6 +69,9 @@
"webDriverBiDi": { "webDriverBiDi": {
"PUPPETEER_PROTOCOL": "webDriverBiDi" "PUPPETEER_PROTOCOL": "webDriverBiDi"
}, },
"cdp": {} "cdp": {},
"tabTarget": {
"PUPPETEER_INTERNAL_TAB_TARGET": "true"
}
} }
} }