mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: fetch Firefox from JSON source instead of RegExp (#5864)
Fetch Firefox from https://product-details.mozilla.org/1.0/firefox_versions.json. Fixes #5742.
This commit is contained in:
parent
69c38fc2d0
commit
b510c354c7
25
install.js
25
install.js
@ -26,6 +26,8 @@
|
||||
|
||||
const compileTypeScriptIfRequired = require('./typescript-if-required');
|
||||
|
||||
const firefoxVersions =
|
||||
'https://product-details.mozilla.org/1.0/firefox_versions.json';
|
||||
const supportedProducts = {
|
||||
chrome: 'Chromium',
|
||||
firefox: 'Firefox Nightly',
|
||||
@ -160,27 +162,22 @@ async function download() {
|
||||
let data = '';
|
||||
logPolitely(`Requesting latest Firefox Nightly version from ${host}`);
|
||||
https
|
||||
.get(host + '/', (r) => {
|
||||
.get(firefoxVersions, (r) => {
|
||||
if (r.statusCode >= 400)
|
||||
return reject(new Error(`Got status code ${r.statusCode}`));
|
||||
r.on('data', (chunk) => {
|
||||
data += chunk;
|
||||
});
|
||||
r.on('end', parseVersion);
|
||||
r.on('end', () => {
|
||||
try {
|
||||
const versions = JSON.parse(data);
|
||||
return resolve(versions.FIREFOX_NIGHTLY);
|
||||
} catch {
|
||||
return reject(new Error('Firefox version not found'));
|
||||
}
|
||||
});
|
||||
})
|
||||
.on('error', reject);
|
||||
|
||||
function parseVersion() {
|
||||
const regex = /firefox\-(?<version>\d\d)\..*/gm;
|
||||
let result = 0;
|
||||
let match;
|
||||
while ((match = regex.exec(data)) !== null) {
|
||||
const version = parseInt(match.groups.version, 10);
|
||||
if (version > result) result = version;
|
||||
}
|
||||
if (result) resolve(result.toString());
|
||||
else reject(new Error('Firefox version not found'));
|
||||
}
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
@ -40,10 +40,10 @@ const downloadURLs = {
|
||||
win64: '%s/chromium-browser-snapshots/Win_x64/%d/%s.zip',
|
||||
},
|
||||
firefox: {
|
||||
linux: '%s/firefox-%s.0a1.en-US.%s-x86_64.tar.bz2',
|
||||
mac: '%s/firefox-%s.0a1.en-US.%s.dmg',
|
||||
win32: '%s/firefox-%s.0a1.en-US.%s.zip',
|
||||
win64: '%s/firefox-%s.0a1.en-US.%s.zip',
|
||||
linux: '%s/firefox-%s.en-US.%s-x86_64.tar.bz2',
|
||||
mac: '%s/firefox-%s.en-US.%s.dmg',
|
||||
win32: '%s/firefox-%s.en-US.%s.zip',
|
||||
win64: '%s/firefox-%s.en-US.%s.zip',
|
||||
},
|
||||
} as const;
|
||||
|
||||
|
@ -81,7 +81,7 @@ describe('Launcher specs', function () {
|
||||
host: server.PREFIX,
|
||||
product: 'firefox',
|
||||
});
|
||||
const expectedVersion = '75';
|
||||
const expectedVersion = '75.0a1';
|
||||
let revisionInfo = browserFetcher.revisionInfo(expectedVersion);
|
||||
server.setRoute(
|
||||
revisionInfo.url.substring(server.PREFIX.length),
|
||||
@ -89,7 +89,7 @@ describe('Launcher specs', function () {
|
||||
server.serveFile(
|
||||
req,
|
||||
res,
|
||||
`/firefox-${expectedVersion}.0a1.en-US.linux-x86_64.tar.bz2`
|
||||
`/firefox-${expectedVersion}.en-US.linux-x86_64.tar.bz2`
|
||||
);
|
||||
}
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user