mirror of
https://github.com/FlareSolverr/FlareSolverr.git
synced 2025-06-08 04:25:25 +00:00
Build native packages with Firefox
This commit is contained in:
parent
2408a75a70
commit
a841d67745
@ -68,8 +68,9 @@ This is the recommended way for Windows users.
|
|||||||
This is the recommended way for macOS users and for developers.
|
This is the recommended way for macOS users and for developers.
|
||||||
* Install [NodeJS](https://nodejs.org/).
|
* Install [NodeJS](https://nodejs.org/).
|
||||||
* Clone this repository and open a shell in that path.
|
* Clone this repository and open a shell in that path.
|
||||||
* Run `PUPPETEER_PRODUCT=firefox npm install` command to install FlareSolverr dependencies.
|
* Run `export PUPPETEER_PRODUCT=firefox` (Linux/macOS) or `set PUPPETEER_PRODUCT=firefox` (Windows).
|
||||||
* Run `PUPPETEER_PRODUCT=firefox node node_modules/puppeteer/install.js` to install Firefox.
|
* Run `npm install` command to install FlareSolverr dependencies.
|
||||||
|
* Run `node node_modules/puppeteer/install.js` to install Firefox.
|
||||||
* Run `npm run build` command to compile TypeScript code.
|
* Run `npm run build` command to compile TypeScript code.
|
||||||
* Run `npm start` command to start FlareSolverr.
|
* Run `npm start` command to start FlareSolverr.
|
||||||
|
|
||||||
|
@ -2,16 +2,39 @@ const fs = require('fs')
|
|||||||
const path = require('path')
|
const path = require('path')
|
||||||
const { execSync } = require('child_process')
|
const { execSync } = require('child_process')
|
||||||
const archiver = require('archiver')
|
const archiver = require('archiver')
|
||||||
|
const https = require('https')
|
||||||
const puppeteer = require('puppeteer')
|
const puppeteer = require('puppeteer')
|
||||||
const version = 'v' + require('./package.json').version;
|
const version = 'v' + require('./package.json').version;
|
||||||
|
|
||||||
// todo: package firefox
|
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 () => {
|
(async () => {
|
||||||
const builds = [
|
const builds = [
|
||||||
{
|
{
|
||||||
platform: 'linux',
|
platform: 'linux',
|
||||||
version: 756035,
|
firefoxFolder: 'firefox',
|
||||||
chromeFolder: 'chrome-linux',
|
|
||||||
fsExec: 'flaresolverr-linux',
|
fsExec: 'flaresolverr-linux',
|
||||||
fsZipExec: 'flaresolverr',
|
fsZipExec: 'flaresolverr',
|
||||||
fsZipName: 'linux-x64',
|
fsZipName: 'linux-x64',
|
||||||
@ -19,18 +42,16 @@ const version = 'v' + require('./package.json').version;
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
platform: 'win64',
|
platform: 'win64',
|
||||||
version: 756035,
|
firefoxFolder: 'firefox',
|
||||||
chromeFolder: 'chrome-win',
|
|
||||||
fsExec: 'flaresolverr-win.exe',
|
fsExec: 'flaresolverr-win.exe',
|
||||||
fsZipExec: 'flaresolverr.exe',
|
fsZipExec: 'flaresolverr.exe',
|
||||||
fsZipName: 'windows-x64',
|
fsZipName: 'windows-x64',
|
||||||
fsLicenseName: 'LICENSE.txt'
|
fsLicenseName: 'LICENSE.txt'
|
||||||
}
|
}
|
||||||
// todo: this is working but changes are required in sessions.ts to find chrome path
|
// todo: this has to be build in macOS (hdiutil is required). changes required in sessions.ts too
|
||||||
// {
|
// {
|
||||||
// platform: 'mac',
|
// platform: 'mac',
|
||||||
// version: 756035,
|
// firefoxFolder: 'firefox',
|
||||||
// chromeFolder: 'chrome-mac',
|
|
||||||
// fsExec: 'flaresolverr-macos',
|
// fsExec: 'flaresolverr-macos',
|
||||||
// fsZipExec: 'flaresolverr',
|
// fsZipExec: 'flaresolverr',
|
||||||
// fsZipName: 'macos',
|
// fsZipName: 'macos',
|
||||||
@ -43,20 +64,24 @@ const version = 'v' + require('./package.json').version;
|
|||||||
if (fs.existsSync('bin')) {
|
if (fs.existsSync('bin')) {
|
||||||
fs.rmSync('bin', { recursive: true })
|
fs.rmSync('bin', { recursive: true })
|
||||||
}
|
}
|
||||||
execSync('pkg -t node14-win-x64,node14-linux-x64 --out-path bin .')
|
execSync('./node_modules/.bin/pkg -t node14-win-x64,node14-linux-x64 --out-path bin .')
|
||||||
// execSync('pkg -t node14-win-x64,node14-mac-x64,node14-linux-x64 --out-path bin .')
|
// execSync('./node_modules/.bin/pkg -t node14-win-x64,node14-mac-x64,node14-linux-x64 --out-path bin .')
|
||||||
|
|
||||||
// download Chrome and zip together
|
// get firefox revision
|
||||||
|
const revision = await getFirefoxNightlyVersion();
|
||||||
|
|
||||||
|
// download firefox and zip together
|
||||||
for (const os of builds) {
|
for (const os of builds) {
|
||||||
console.log('Building ' + os.fsZipName + ' artifact')
|
console.log('Building ' + os.fsZipName + ' artifact')
|
||||||
|
|
||||||
// download chrome
|
// download firefox
|
||||||
console.log('Downloading Chrome...')
|
console.log(`Downloading firefox ${revision} for ${os.platform} ...`)
|
||||||
const f = puppeteer.createBrowserFetcher({
|
const f = puppeteer.createBrowserFetcher({
|
||||||
|
product: 'firefox',
|
||||||
platform: os.platform,
|
platform: os.platform,
|
||||||
path: path.join(__dirname, 'bin', 'puppeteer')
|
path: path.join(__dirname, 'bin', 'puppeteer')
|
||||||
})
|
})
|
||||||
await f.download(os.version)
|
await f.download(revision)
|
||||||
|
|
||||||
// compress in zip
|
// compress in zip
|
||||||
console.log('Compressing zip file...')
|
console.log('Compressing zip file...')
|
||||||
@ -76,7 +101,7 @@ const version = 'v' + require('./package.json').version;
|
|||||||
|
|
||||||
archive.file('LICENSE', { name: 'flaresolverr/' + os.fsLicenseName })
|
archive.file('LICENSE', { name: 'flaresolverr/' + os.fsLicenseName })
|
||||||
archive.file('bin/' + os.fsExec, { name: 'flaresolverr/' + os.fsZipExec })
|
archive.file('bin/' + os.fsExec, { name: 'flaresolverr/' + os.fsZipExec })
|
||||||
archive.directory('bin/puppeteer/' + os.platform + '-' + os.version + '/' + os.chromeFolder, 'flaresolverr/chrome')
|
archive.directory('bin/puppeteer/' + os.platform + '-' + revision + '/' + os.firefoxFolder, 'flaresolverr/firefox')
|
||||||
if (os.platform === 'linux') {
|
if (os.platform === 'linux') {
|
||||||
archive.file('flaresolverr.service', { name: 'flaresolverr/flaresolverr.service' })
|
archive.file('flaresolverr.service', { name: 'flaresolverr/flaresolverr.service' })
|
||||||
}
|
}
|
||||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -18,7 +18,7 @@
|
|||||||
"uuid": "^8.3.2"
|
"uuid": "^8.3.2"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"flaresolverr": "dist/index.js"
|
"flaresolverr": "dist/server.js"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/await-timeout": "^0.3.1",
|
"@types/await-timeout": "^0.3.1",
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
"url": "https://github.com/ngosang/FlareSolverr"
|
"url": "https://github.com/ngosang/FlareSolverr"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"flaresolverr": "dist/index.js"
|
"flaresolverr": "dist/server.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"await-timeout": "^1.1.1",
|
"await-timeout": "^1.1.1",
|
||||||
|
@ -111,11 +111,10 @@ export async function create(session: string, options: SessionCreateOptions): Pr
|
|||||||
log.debug('Creating userDataDir for session.')
|
log.debug('Creating userDataDir for session.')
|
||||||
puppeteerOptions.userDataDir = prepareBrowserProfile(sessionId, options.proxy)
|
puppeteerOptions.userDataDir = prepareBrowserProfile(sessionId, options.proxy)
|
||||||
|
|
||||||
// todo: fix native package with firefox
|
|
||||||
// if we are running inside executable binary, change browser path
|
// if we are running inside executable binary, change browser path
|
||||||
if (typeof (process as any).pkg !== 'undefined') {
|
if (typeof (process as any).pkg !== 'undefined') {
|
||||||
const exe = process.platform === "win32" ? 'chrome.exe' : 'chrome';
|
const exe = process.platform === "win32" ? 'firefox.exe' : 'firefox';
|
||||||
puppeteerOptions.executablePath = path.join(path.dirname(process.execPath), 'chrome', exe)
|
puppeteerOptions.executablePath = path.join(path.dirname(process.execPath), 'firefox', exe)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug('Launching web browser...')
|
log.debug('Launching web browser...')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user