Skip to content

Commit 19ecc6f

Browse files
committed
prefer chrome to chromium, distinguish between old and new verb requirements. Closes #4653
1 parent ab6679e commit 19ecc6f

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

src/core/cri/cri.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,31 @@ export async function criClient(appPath?: string, port?: number) {
7676
}
7777
const app: string = appPath || await getBrowserExecutablePath();
7878

79+
const version = Deno.run({
80+
cmd: [app, "--version"],
81+
stdout: "piped",
82+
stderr: "piped",
83+
});
84+
const [status, stdout, _stderr] = await Promise.all([
85+
version.status(),
86+
version.output(),
87+
version.stderrOutput(),
88+
]);
89+
if (!status.success) {
90+
throw new Error(`Failed to get chrome version`);
91+
}
92+
const versionString = new TextDecoder().decode(stdout);
93+
let versionNumber = 0;
94+
95+
const chromeMatch = versionString.match(/Google Chrome (\d+)/);
96+
if (chromeMatch) {
97+
versionNumber = Number(chromeMatch[1]);
98+
}
99+
const chromiumMatch = versionString.match(/Chromium (\d+)/);
100+
if (chromiumMatch) {
101+
versionNumber = Number(chromiumMatch[1]);
102+
}
103+
79104
const cmd = [
80105
app,
81106
"--headless",
@@ -113,7 +138,7 @@ export async function criClient(appPath?: string, port?: number) {
113138
const maxTries = 5;
114139
for (let i = 0; i < maxTries; ++i) {
115140
try {
116-
client = await cdp({ port });
141+
client = await cdp({ port, version: versionNumber });
117142
break;
118143
} catch (e) {
119144
if (i === maxTries - 1) {

src/core/cri/deno-cri/devtools.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ export async function New(options) {
5050
if (Object.prototype.hasOwnProperty.call(options, "url")) {
5151
options.path += `?${options.url}`;
5252
}
53+
// we don't mutate here because we don't want other
54+
// calls to have PUT as the method
55+
if (options.version >= 109) {
56+
options = {
57+
...options,
58+
method: "PUT",
59+
};
60+
}
5361
const result = await devToolsInterface(options);
5462
return JSON.parse(result);
5563
}

src/core/cri/deno-cri/external-request.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ export default async function externalRequest(options) {
1818
}*/
1919

2020
const url = `${options.protocol}:/${options.host}:${options.port}${options.path}`;
21-
const response = await fetch(url);
21+
const fetchOpts = {};
22+
if (options.method) {
23+
fetchOpts.method = options.method;
24+
}
25+
const response = await fetch(url, options);
2226
const text = await response.text();
2327

2428
if (response.status !== 200) {

src/core/puppeteer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,18 +244,18 @@ export async function getBrowserExecutablePath() {
244244

245245
let executablePath: string | undefined = undefined;
246246

247-
if (availableRevisions.length > 0) {
247+
if (executablePath === undefined) {
248+
executablePath = await findChrome();
249+
}
250+
251+
if (executablePath === undefined && availableRevisions.length > 0) {
248252
// get the latest available revision
249253
availableRevisions.sort((a: string, b: string) => Number(b) - Number(a));
250254
const revision = availableRevisions[0];
251255
const revisionInfo = browserFetcher.revisionInfo(revision);
252256
executablePath = revisionInfo.executablePath;
253257
}
254258

255-
if (executablePath === undefined) {
256-
executablePath = await findChrome();
257-
}
258-
259259
if (executablePath === undefined) {
260260
error("Chrome not found");
261261
info(

0 commit comments

Comments
 (0)