Skip to content

Commit

Permalink
feat: sync chrome-for-testing binary (#455)
Browse files Browse the repository at this point in the history
> puppeteer/puppeteer#10131 Puppeteer has
updated the default browser to Chrome and added the corresponding
implementation as follows:

🧶 Added a new category `/-/binary/` for Chrome , exp:
`/-/binary/chrome-for-testing/113.0.5672.63/mac-arm64/chrome-mac-arm64.zip`

-----------

> puppeteer/puppeteer#10131 puppeteer
更新了默认浏览器为 chrome,新增对应实现

🧶 `/-/binary/` 新增 chrome binary 分类,
示例链接`/-/binary/chrome-for-testing/113.0.5672.63/mac-arm64/chrome-mac-arm64.zip`
  • Loading branch information
elrrrrrrr authored May 5, 2023
1 parent c1fc1a5 commit dd7d73e
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 1 deletion.
69 changes: 69 additions & 0 deletions app/common/adapter/binary/ChromeForTestingBinary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { SingletonProto } from '@eggjs/tegg';
import { BinaryType } from '../../enum/Binary';
import { AbstractBinary, FetchResult, BinaryItem, BinaryAdapter } from './AbstractBinary';

@SingletonProto()
@BinaryAdapter(BinaryType.ChromeForTesting)
export class ChromeForTestingBinary extends AbstractBinary {
private dirItems?: {
[key: string]: BinaryItem[];
};

async init() {
this.dirItems = undefined;
}

async fetch(dir: string): Promise<FetchResult | undefined> {
if (!this.dirItems) {
this.dirItems = {};
this.dirItems['/'] = [];
let chromeVersion = '';

// exports.PUPPETEER_REVISIONS = Object.freeze({
// chrome: '113.0.5672.63',
// firefox: 'latest',
// });
const unpkgURL = 'https://unpkg.com/puppeteer-core@latest/lib/cjs/puppeteer/revisions.js';
const text = await this.requestXml(unpkgURL);
const m = /chrome:\s+\'([\d\.]+)\'\,/.exec(text);
if (m) {
chromeVersion = m[1];
}

const platforms = [ 'linux64', 'mac-arm64', 'mac-x64', 'win32', 'win64' ];
const date = new Date().toISOString();
this.dirItems['/'].push({
name: `${chromeVersion}/`,
date,
size: '-',
isDir: true,
url: '',
});
this.dirItems[`/${chromeVersion}/`] = [];

for (const platform of platforms) {
this.dirItems[`/${chromeVersion}/`].push({
name: `${platform}/`,
date,
size: '-',
isDir: true,
url: '',
});

// https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/113.0.5672.63/mac-arm64/chrome-mac-arm64.zip
const name = `chrome-${platform}.zip`;
this.dirItems[`/${chromeVersion}/${platform}/`] = [
{
name,
date,
size: '-',
isDir: false,
url: `https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/${chromeVersion}/${platform}/${name}`,
},
];
}
}

return { items: this.dirItems[dir], nextParams: null };
}
}
1 change: 1 addition & 0 deletions app/common/enum/Binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export enum BinaryType {
Playwright = 'playwright',
Puppeteer = 'puppeteer',
Sqlcipher = 'sqlcipher',
ChromeForTesting = 'chromeForTesting',
}
10 changes: 9 additions & 1 deletion config/binaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,22 @@ const binaries = {
repo: 'journeyapps/node-sqlcipher',
distUrl: 'https://journeyapps-node-binary.s3.amazonaws.com',
},
// PuppeteerBinary
// puppeteer binary
'chromium-browser-snapshots': {
category: 'chromium-browser-snapshots',
description: 'chromium-browser-snapshots sync for puppeteer',
type: BinaryType.Puppeteer,
repo: 'puppeteer/puppeteer',
distUrl: 'https://chromium-browser-snapshots.storage.googleapis.com/?delimiter=/&prefix=',
},
// ChromeBinary
'chrome-for-testing': {
category: 'chrome-for-testing',
description: 'chrome-for-testing for puppeteer',
type: BinaryType.ChromeForTesting,
repo: 'puppeteer/puppeteer',
distUrl: 'https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/',
},
// NodePreGypBinary
'grpc-tools': {
category: 'grpc-tools',
Expand Down
29 changes: 29 additions & 0 deletions test/common/adapter/binary/ChromeForTestingBinary.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import assert from 'assert';
import { app } from 'egg-mock/bootstrap';
import { ChromeForTestingBinary } from 'app/common/adapter/binary/ChromeForTestingBinary';

describe('test/common/adapter/binary/ChromeForTestingBinary.test.ts', () => {
let binary: ChromeForTestingBinary;
beforeEach(async () => {
binary = await app.getEggObject(ChromeForTestingBinary);
});
describe('fetch()', () => {
it('should work for chrome binary', async () => {
const result = await binary.fetch('/');
const latestVersion = result?.items?.[0].name;
assert(latestVersion);

const platformRes = await binary.fetch(`/${latestVersion}`);
const platforms = platformRes?.items.map(item => item.name);
assert(platforms);

for (const platform of platforms) {
const versionRes = await binary.fetch(`/${latestVersion}${platform}`);
const versions = versionRes?.items.map(item => item.name);
assert.equal(versions?.length, 1);
assert(versionRes?.items[0].name);
assert.equal(versionRes?.items[0].isDir, false);
}
});
});
});

0 comments on commit dd7d73e

Please sign in to comment.