Install Firefox 94 instead of the latest Nightly

This commit is contained in:
ngosang 2022-07-30 22:21:20 +02:00
parent e505f906ea
commit 3ed7cc713e
6 changed files with 51 additions and 56 deletions

View File

@ -1,9 +1,4 @@
FROM --platform=${TARGETPLATFORM:-linux/amd64} node:16-alpine3.15
# Print build information
ARG TARGETPLATFORM
ARG BUILDPLATFORM
RUN printf "I am running on ${BUILDPLATFORM:-linux/amd64}, building for ${TARGETPLATFORM:-linux/amd64}\n$(uname -a)\n"
FROM node:16-alpine3.15
# Install the web browser (package firefox-esr is available too)
RUN apk update && \
@ -14,7 +9,7 @@ RUN apk update && \
USER node
RUN mkdir -p /home/node/flaresolverr
WORKDIR /home/node/flaresolverr
COPY --chown=node:node package.json package-lock.json tsconfig.json ./
COPY --chown=node:node package.json package-lock.json tsconfig.json install.js ./
COPY --chown=node:node src ./src/
# Install package. Skip installing the browser, we will use the installed package.

View File

@ -72,11 +72,11 @@ This is the recommended way for Windows users.
This is the recommended way for macOS users and for developers.
* Install [NodeJS](https://nodejs.org/) 16.
* Clone this repository and open a shell in that path.
* Run `export PUPPETEER_PRODUCT=firefox` (Linux/macOS) or `set PUPPETEER_PRODUCT=firefox` (Windows).
* Run `export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true` (Linux/macOS) or `set PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true` (Windows).
* Run `npm install` command to install FlareSolverr dependencies.
* Run `npm start` command to compile TypeScript code and start FlareSolverr.
If you get errors related to firefox not installed try running `node node_modules/puppeteer/install.js` to install Firefox.
If you get errors related to firefox not installed try running `node install.js` to install Firefox.
### Systemd service

View File

@ -6,30 +6,6 @@ const https = require('https')
const puppeteer = require('puppeteer')
const version = 'v' + require('./package.json').version;
function getFirefoxNightlyVersion() {
const firefoxVersions = 'https://product-details.mozilla.org/1.0/firefox_versions.json';
return new Promise((resolve, reject) => {
let data = '';
https
.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', () => {
try {
const versions = JSON.parse(data);
return resolve(versions.FIREFOX_NIGHTLY);
} catch {
return reject(new Error('Firefox version not found'));
}
});
})
.on('error', reject);
});
}
(async () => {
const builds = [
{
@ -67,8 +43,10 @@ function getFirefoxNightlyVersion() {
execSync('./node_modules/.bin/pkg -t node16-win-x64,node16-linux-x64 --out-path bin .')
// execSync('./node_modules/.bin/pkg -t node16-win-x64,node16-mac-x64,node16-linux-x64 --out-path bin .')
// get firefox revision
const revision = await getFirefoxNightlyVersion();
// Puppeteer does not allow to download Firefox revisions, just the last Nightly
// We this script we can download any version
const revision = '94.0a1';
const downloadHost = 'https://archive.mozilla.org/pub/firefox/nightly/2021/10/2021-10-01-09-33-23-mozilla-central';
// download firefox and zip together
for (const os of builds) {
@ -79,6 +57,7 @@ function getFirefoxNightlyVersion() {
const f = puppeteer.createBrowserFetcher({
product: 'firefox',
platform: os.platform,
host: downloadHost,
path: path.join(__dirname, 'bin', 'puppeteer')
})
await f.download(revision)

40
install.js Normal file
View File

@ -0,0 +1,40 @@
const fs = require('fs');
const puppeteer = require('puppeteer');
(async () => {
// Puppeteer does not allow to download Firefox revisions, just the last Nightly
// We this script we can download any version
const revision = '94.0a1';
const downloadHost = 'https://archive.mozilla.org/pub/firefox/nightly/2021/10/2021-10-01-09-33-23-mozilla-central';
// skip installation (for Dockerfile)
if (process.env.PUPPETEER_EXECUTABLE_PATH) {
console.log('Skipping Firefox installation because the environment variable "PUPPETEER_EXECUTABLE_PATH" is set.');
return;
}
// check if Firefox is already installed
const f = puppeteer.createBrowserFetcher({
product: 'firefox',
host: downloadHost
})
if (fs.existsSync(f._getFolderPath(revision))) {
console.log(`Firefox ${revision} already installed...`)
return;
}
console.log(`Installing firefox ${revision} ...`)
const downloadPath = f._downloadsFolder;
console.log(`Download path: ${downloadPath}`)
if (fs.existsSync(downloadPath)) {
console.log(`Removing previous downloads...`)
fs.rmSync(downloadPath, { recursive: true })
}
console.log(`Downloading firefox ${revision} ...`)
await f.download(revision)
console.log('Installation complete...')
})()

22
package-lock.json generated
View File

@ -7,6 +7,7 @@
"": {
"name": "flaresolverr",
"version": "2.2.4",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {
"await-timeout": "^1.1.1",
@ -2963,20 +2964,6 @@
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw=="
},
"node_modules/fsevents": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
"dev": true,
"hasInstallScript": true,
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
}
},
"node_modules/function-bind": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
@ -9056,13 +9043,6 @@
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw=="
},
"fsevents": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
"dev": true,
"optional": true
},
"function-bind": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",

View File

@ -3,6 +3,7 @@
"version": "2.2.4",
"description": "Proxy server to bypass Cloudflare protection.",
"scripts": {
"install": "node install.js",
"start": "tsc && node ./dist/server.js",
"build": "tsc",
"dev": "nodemon -e ts --exec ts-node src/server.ts",