mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: implement acceptInsecureCerts and version for BiDi (#10365)
This commit is contained in:
parent
3c41b3ec78
commit
903afc3715
@ -20,6 +20,6 @@ Promise<string>
|
|||||||
|
|
||||||
## Remarks
|
## Remarks
|
||||||
|
|
||||||
For headless browser, this is similar to `HeadlessChrome/61.0.3153.0`. For non-headless, this is similar to `Chrome/61.0.3153.0`.
|
For headless browser, this is similar to `HeadlessChrome/61.0.3153.0`. For non-headless or new-headless, this is similar to `Chrome/61.0.3153.0`. For Firefox, it is similar to `Firefox/116.0a1`.
|
||||||
|
|
||||||
The format of browser.version() might change with future releases of browsers.
|
The format of browser.version() might change with future releases of browsers.
|
||||||
|
@ -405,9 +405,11 @@ export class Browser extends EventEmitter {
|
|||||||
* @remarks
|
* @remarks
|
||||||
*
|
*
|
||||||
* For headless browser, this is similar to `HeadlessChrome/61.0.3153.0`. For
|
* For headless browser, this is similar to `HeadlessChrome/61.0.3153.0`. For
|
||||||
* non-headless, this is similar to `Chrome/61.0.3153.0`.
|
* non-headless or new-headless, this is similar to `Chrome/61.0.3153.0`. For
|
||||||
|
* Firefox, it is similar to `Firefox/116.0a1`.
|
||||||
*
|
*
|
||||||
* The format of browser.version() might change with future releases of browsers.
|
* The format of browser.version() might change with future releases of
|
||||||
|
* browsers.
|
||||||
*/
|
*/
|
||||||
version(): Promise<string> {
|
version(): Promise<string> {
|
||||||
throw new Error('Not implemented');
|
throw new Error('Not implemented');
|
||||||
|
@ -29,24 +29,44 @@ import {Viewport} from '../PuppeteerViewport.js';
|
|||||||
|
|
||||||
import {BrowserContext} from './BrowserContext.js';
|
import {BrowserContext} from './BrowserContext.js';
|
||||||
import {Connection} from './Connection.js';
|
import {Connection} from './Connection.js';
|
||||||
|
import {debugError} from './utils.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
export class Browser extends BrowserBase {
|
export class Browser extends BrowserBase {
|
||||||
static readonly subscribeModules = ['browsingContext', 'network', 'log'];
|
static readonly subscribeModules = ['browsingContext', 'network', 'log'];
|
||||||
|
#browserName = '';
|
||||||
|
#browserVersion = '';
|
||||||
|
|
||||||
static async create(opts: Options): Promise<Browser> {
|
static async create(opts: Options): Promise<Browser> {
|
||||||
|
let browserName = '';
|
||||||
|
let browserVersion = '';
|
||||||
|
|
||||||
// TODO: await until the connection is established.
|
// TODO: await until the connection is established.
|
||||||
try {
|
try {
|
||||||
await opts.connection.send('session.new', {capabilities: {}});
|
const {result} = await opts.connection.send('session.new', {
|
||||||
} catch {}
|
capabilities: {
|
||||||
|
alwaysMatch: {
|
||||||
|
acceptInsecureCerts: opts.ignoreHTTPSErrors,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
browserName = result.capabilities.browserName ?? '';
|
||||||
|
browserVersion = result.capabilities.browserVersion ?? '';
|
||||||
|
} catch (err) {
|
||||||
|
debugError(err);
|
||||||
|
}
|
||||||
|
|
||||||
await opts.connection.send('session.subscribe', {
|
await opts.connection.send('session.subscribe', {
|
||||||
events: Browser.subscribeModules as Bidi.Message.EventNames[],
|
events: Browser.subscribeModules as Bidi.Message.EventNames[],
|
||||||
});
|
});
|
||||||
|
|
||||||
return new Browser(opts);
|
return new Browser({
|
||||||
|
...opts,
|
||||||
|
browserName,
|
||||||
|
browserVersion,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#process?: ChildProcess;
|
#process?: ChildProcess;
|
||||||
@ -54,12 +74,19 @@ export class Browser extends BrowserBase {
|
|||||||
#connection: Connection;
|
#connection: Connection;
|
||||||
#defaultViewport: Viewport | null;
|
#defaultViewport: Viewport | null;
|
||||||
|
|
||||||
constructor(opts: Options) {
|
constructor(
|
||||||
|
opts: Options & {
|
||||||
|
browserName: string;
|
||||||
|
browserVersion: string;
|
||||||
|
}
|
||||||
|
) {
|
||||||
super();
|
super();
|
||||||
this.#process = opts.process;
|
this.#process = opts.process;
|
||||||
this.#closeCallback = opts.closeCallback;
|
this.#closeCallback = opts.closeCallback;
|
||||||
this.#connection = opts.connection;
|
this.#connection = opts.connection;
|
||||||
this.#defaultViewport = opts.defaultViewport;
|
this.#defaultViewport = opts.defaultViewport;
|
||||||
|
this.#browserName = opts.browserName;
|
||||||
|
this.#browserVersion = opts.browserVersion;
|
||||||
|
|
||||||
this.#process?.on('close', () => {
|
this.#process?.on('close', () => {
|
||||||
return this.emit(BrowserEmittedEvents.Disconnected);
|
return this.emit(BrowserEmittedEvents.Disconnected);
|
||||||
@ -90,6 +117,10 @@ export class Browser extends BrowserBase {
|
|||||||
defaultViewport: this.#defaultViewport,
|
defaultViewport: this.#defaultViewport,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override async version(): Promise<string> {
|
||||||
|
return `${this.#browserName}/${this.#browserVersion}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Options {
|
interface Options {
|
||||||
@ -97,4 +128,5 @@ interface Options {
|
|||||||
closeCallback?: BrowserCloseCallback;
|
closeCallback?: BrowserCloseCallback;
|
||||||
connection: Connection;
|
connection: Connection;
|
||||||
defaultViewport: Viewport | null;
|
defaultViewport: Viewport | null;
|
||||||
|
ignoreHTTPSErrors?: boolean;
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,29 @@ import {BrowsingContext} from './BrowsingContext.js';
|
|||||||
const debugProtocolSend = debug('puppeteer:webDriverBiDi:SEND ►');
|
const debugProtocolSend = debug('puppeteer:webDriverBiDi:SEND ►');
|
||||||
const debugProtocolReceive = debug('puppeteer:webDriverBiDi:RECV ◀');
|
const debugProtocolReceive = debug('puppeteer:webDriverBiDi:RECV ◀');
|
||||||
|
|
||||||
|
type Capability = {
|
||||||
|
// session.CapabilityRequest = {
|
||||||
|
// ? acceptInsecureCerts: bool,
|
||||||
|
// ? browserName: text,
|
||||||
|
// ? browserVersion: text,
|
||||||
|
// ? platformName: text,
|
||||||
|
// ? proxy: {
|
||||||
|
// ? proxyType: "pac" / "direct" / "autodetect" / "system" / "manual",
|
||||||
|
// ? proxyAutoconfigUrl: text,
|
||||||
|
// ? ftpProxy: text,
|
||||||
|
// ? httpProxy: text,
|
||||||
|
// ? noProxy: [*text],
|
||||||
|
// ? sslProxy: text,
|
||||||
|
// ? socksProxy: text,
|
||||||
|
// ? socksVersion: 0..255,
|
||||||
|
// },
|
||||||
|
// Extensible
|
||||||
|
// };
|
||||||
|
acceptInsecureCerts?: boolean;
|
||||||
|
browserName?: string;
|
||||||
|
browserVersion?: string;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
@ -73,8 +96,19 @@ interface Commands {
|
|||||||
};
|
};
|
||||||
|
|
||||||
'session.new': {
|
'session.new': {
|
||||||
params: {capabilities?: Record<any, unknown>}; // TODO: Update Types in chromium bidi
|
params: {
|
||||||
returnType: {sessionId: string};
|
// capabilities: session.CapabilitiesRequest
|
||||||
|
capabilities?: {
|
||||||
|
// session.CapabilitiesRequest = {
|
||||||
|
// ? alwaysMatch: session.CapabilityRequest,
|
||||||
|
// ? firstMatch: [*session.CapabilityRequest]
|
||||||
|
// }
|
||||||
|
alwaysMatch?: Capability;
|
||||||
|
};
|
||||||
|
}; // TODO: Update Types in chromium bidi
|
||||||
|
returnType: {
|
||||||
|
result: {sessionId: string; capabilities: Capability};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
'session.status': {
|
'session.status': {
|
||||||
params: object;
|
params: object;
|
||||||
|
@ -143,6 +143,7 @@ export class ProductLauncher {
|
|||||||
protocolTimeout,
|
protocolTimeout,
|
||||||
slowMo,
|
slowMo,
|
||||||
defaultViewport,
|
defaultViewport,
|
||||||
|
ignoreHTTPSErrors,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -169,6 +170,7 @@ export class ProductLauncher {
|
|||||||
protocolTimeout,
|
protocolTimeout,
|
||||||
slowMo,
|
slowMo,
|
||||||
defaultViewport,
|
defaultViewport,
|
||||||
|
ignoreHTTPSErrors,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -329,6 +331,7 @@ export class ProductLauncher {
|
|||||||
protocolTimeout: number | undefined;
|
protocolTimeout: number | undefined;
|
||||||
slowMo: number;
|
slowMo: number;
|
||||||
defaultViewport: Viewport | null;
|
defaultViewport: Viewport | null;
|
||||||
|
ignoreHTTPSErrors?: boolean;
|
||||||
}
|
}
|
||||||
): Promise<Browser> {
|
): Promise<Browser> {
|
||||||
// TODO: use other options too.
|
// TODO: use other options too.
|
||||||
@ -341,6 +344,7 @@ export class ProductLauncher {
|
|||||||
closeCallback,
|
closeCallback,
|
||||||
process: browserProcess.nodeProcess,
|
process: browserProcess.nodeProcess,
|
||||||
defaultViewport: opts.defaultViewport,
|
defaultViewport: opts.defaultViewport,
|
||||||
|
ignoreHTTPSErrors: opts.ignoreHTTPSErrors,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,6 +359,7 @@ export class ProductLauncher {
|
|||||||
protocolTimeout: number | undefined;
|
protocolTimeout: number | undefined;
|
||||||
slowMo: number;
|
slowMo: number;
|
||||||
defaultViewport: Viewport | null;
|
defaultViewport: Viewport | null;
|
||||||
|
ignoreHTTPSErrors?: boolean;
|
||||||
}
|
}
|
||||||
): Promise<Browser> {
|
): Promise<Browser> {
|
||||||
const browserWSEndpoint =
|
const browserWSEndpoint =
|
||||||
@ -377,6 +382,7 @@ export class ProductLauncher {
|
|||||||
closeCallback,
|
closeCallback,
|
||||||
process: browserProcess.nodeProcess,
|
process: browserProcess.nodeProcess,
|
||||||
defaultViewport: opts.defaultViewport,
|
defaultViewport: opts.defaultViewport,
|
||||||
|
ignoreHTTPSErrors: opts.ignoreHTTPSErrors,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,6 +269,12 @@
|
|||||||
"parameters": ["webDriverBiDi"],
|
"parameters": ["webDriverBiDi"],
|
||||||
"expectations": ["PASS"]
|
"expectations": ["PASS"]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"testIdPattern": "[browser.spec] Browser specs Browser.version should return version",
|
||||||
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
|
"parameters": ["firefox", "webDriverBiDi"],
|
||||||
|
"expectations": ["PASS"]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"testIdPattern": "[chromiumonly.spec] *",
|
"testIdPattern": "[chromiumonly.spec] *",
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
|
@ -37,12 +37,10 @@ describe('WebDriver BiDi', () => {
|
|||||||
const transport = new TestConnectionTransport();
|
const transport = new TestConnectionTransport();
|
||||||
const connection = new Connection(transport);
|
const connection = new Connection(transport);
|
||||||
const responsePromise = connection.send('session.new', {
|
const responsePromise = connection.send('session.new', {
|
||||||
capabilities: {
|
capabilities: {},
|
||||||
proxy: {},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
expect(transport.sent).toEqual([
|
expect(transport.sent).toEqual([
|
||||||
`{"id":1,"method":"session.new","params":{"capabilities":{"proxy":{}}}}`,
|
`{"id":1,"method":"session.new","params":{"capabilities":{}}}`,
|
||||||
]);
|
]);
|
||||||
const id = JSON.parse(transport.sent[0]!).id;
|
const id = JSON.parse(transport.sent[0]!).id;
|
||||||
const rawResponse = {
|
const rawResponse = {
|
||||||
|
@ -22,14 +22,12 @@ describe('Browser specs', function () {
|
|||||||
setupTestBrowserHooks();
|
setupTestBrowserHooks();
|
||||||
|
|
||||||
describe('Browser.version', function () {
|
describe('Browser.version', function () {
|
||||||
it('should return whether we are in headless', async () => {
|
it('should return version', async () => {
|
||||||
const {browser, isHeadless, headless} = getTestState();
|
const {browser} = getTestState();
|
||||||
|
|
||||||
const version = await browser.version();
|
const version = await browser.version();
|
||||||
expect(version.length).toBeGreaterThan(0);
|
expect(version.length).toBeGreaterThan(0);
|
||||||
expect(version.startsWith('Headless')).toBe(
|
expect(version.toLowerCase()).atLeastOneToContain(['firefox', 'chrome']);
|
||||||
isHeadless && headless !== 'new'
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user