How to use getChromiumRevision method in Puppeteer

Best JavaScript code snippet using puppeteer

bisect.js

Source:bisect.js Github

copy

Full Screen

...44 console.log(help);45 process.exit(0);46}47if (typeof argv.good !== 'number') {48 argv.good = getChromiumRevision('main');49 if (typeof argv.good !== 'number') {50 console.log(51 COLOR_RED +52 'ERROR: Could not parse current Chromium revision' +53 COLOR_RESET54 );55 console.log(help);56 process.exit(1);57 }58}59if (typeof argv.bad !== 'number') {60 argv.bad = getChromiumRevision();61 if (typeof argv.bad !== 'number') {62 console.log(63 COLOR_RED +64 'ERROR: Could not parse Chromium revision in the main branch' +65 COLOR_RESET66 );67 console.log(help);68 process.exit(1);69 }70}71if (!argv.script && !argv['unit-test']) {72 console.log(73 COLOR_RED +74 'ERROR: Expected to be given a script or a unit test to run' +75 COLOR_RESET76 );77 console.log(help);78 process.exit(1);79}80const scriptPath = argv.script ? path.resolve(argv.script) : null;81if (argv.script && !fs.existsSync(scriptPath)) {82 console.log(83 COLOR_RED +84 'ERROR: Expected to be given a path to a script to run' +85 COLOR_RESET86 );87 console.log(help);88 process.exit(1);89}90(async (scriptPath, good, bad, pattern, noCache) => {91 const span = Math.abs(good - bad);92 console.log(93 `Bisecting ${COLOR_YELLOW}${span}${COLOR_RESET} revisions in ${COLOR_YELLOW}~${94 span.toString(2).length95 }${COLOR_RESET} iterations`96 );97 while (true) {98 const middle = Math.round((good + bad) / 2);99 const revision = await findDownloadableRevision(middle, good, bad);100 if (!revision || revision === good || revision === bad) break;101 let info = browserFetcher.revisionInfo(revision);102 const shouldRemove = noCache && !info.local;103 info = await downloadRevision(revision);104 const exitCode = await (pattern105 ? runUnitTest(pattern, info)106 : runScript(scriptPath, info));107 if (shouldRemove) await browserFetcher.remove(revision);108 let outcome;109 if (exitCode) {110 bad = revision;111 outcome = COLOR_RED + 'BAD' + COLOR_RESET;112 } else {113 good = revision;114 outcome = COLOR_GREEN + 'GOOD' + COLOR_RESET;115 }116 const span = Math.abs(good - bad);117 let fromText = '';118 let toText = '';119 if (good < bad) {120 fromText = COLOR_GREEN + good + COLOR_RESET;121 toText = COLOR_RED + bad + COLOR_RESET;122 } else {123 fromText = COLOR_RED + bad + COLOR_RESET;124 toText = COLOR_GREEN + good + COLOR_RESET;125 }126 console.log(127 `- ${COLOR_YELLOW}r${revision}${COLOR_RESET} was ${outcome}. Bisecting [${fromText}, ${toText}] - ${COLOR_YELLOW}${span}${COLOR_RESET} revisions and ${COLOR_YELLOW}~${128 span.toString(2).length129 }${COLOR_RESET} iterations`130 );131 }132 const [fromSha, toSha] = await Promise.all([133 revisionToSha(Math.min(good, bad)),134 revisionToSha(Math.max(good, bad)),135 ]);136 console.log(137 `RANGE: https://chromium.googlesource.com/chromium/src/+log/${fromSha}..${toSha}`138 );139})(scriptPath, argv.good, argv.bad, argv['unit-test'], argv['no-cache']);140function runScript(scriptPath, revisionInfo) {141 const log = debug('bisect:runscript');142 log('Running script');143 const child = fork(scriptPath, [], {144 stdio: ['inherit', 'inherit', 'inherit', 'ipc'],145 env: {146 ...process.env,147 PUPPETEER_EXECUTABLE_PATH: revisionInfo.executablePath,148 },149 });150 return new Promise((resolve, reject) => {151 child.on('error', (err) => reject(err));152 child.on('exit', (code) => resolve(code));153 });154}155function runUnitTest(pattern, revisionInfo) {156 const log = debug('bisect:rununittest');157 log('Running unit test');158 const child = spawn('npm run unit', ['--', '-g', pattern], {159 stdio: ['inherit', 'inherit', 'inherit', 'ipc'],160 shell: true,161 env: {162 ...process.env,163 PUPPETEER_EXECUTABLE_PATH: revisionInfo.executablePath,164 },165 });166 return new Promise((resolve, reject) => {167 child.on('error', (err) => reject(err));168 child.on('exit', (code) => resolve(code));169 });170}171async function downloadRevision(revision) {172 const log = debug('bisect:download');173 log(`Downloading ${revision}`);174 let progressBar = null;175 let lastDownloadedBytes = 0;176 return await browserFetcher.download(177 revision,178 (downloadedBytes, totalBytes) => {179 if (!progressBar) {180 const ProgressBar = require('progress');181 progressBar = new ProgressBar(182 `- downloading Chromium r${revision} - ${toMegabytes(183 totalBytes184 )} [:bar] :percent :etas `,185 {186 complete: '=',187 incomplete: ' ',188 width: 20,189 total: totalBytes,190 }191 );192 }193 const delta = downloadedBytes - lastDownloadedBytes;194 lastDownloadedBytes = downloadedBytes;195 progressBar.tick(delta);196 }197 );198 function toMegabytes(bytes) {199 const mb = bytes / 1024 / 1024;200 return `${Math.round(mb * 10) / 10} Mb`;201 }202}203async function findDownloadableRevision(rev, from, to) {204 const log = debug('bisect:findrev');205 const min = Math.min(from, to);206 const max = Math.max(from, to);207 log(`Looking around ${rev} from [${min}, ${max}]`);208 if (await browserFetcher.canDownload(rev)) return rev;209 let down = rev;210 let up = rev;211 while (min <= down || up <= max) {212 const [downOk, upOk] = await Promise.all([213 down > min ? probe(--down) : Promise.resolve(false),214 up < max ? probe(++up) : Promise.resolve(false),215 ]);216 if (downOk) return down;217 if (upOk) return up;218 }219 return null;220 async function probe(rev) {221 const result = await browserFetcher.canDownload(rev);222 log(` ${rev} - ${result ? 'OK' : 'missing'}`);223 return result;224 }225}226async function revisionToSha(revision) {227 const json = await fetchJSON(228 'https://cr-rev.appspot.com/_ah/api/crrev/v1/redirect/' + revision229 );230 return json.git_sha;231}232function fetchJSON(url) {233 return new Promise((resolve, reject) => {234 const agent = url.startsWith('https://')235 ? require('https')236 : require('http');237 const options = URL.parse(url);238 options.method = 'GET';239 options.headers = {240 'Content-Type': 'application/json',241 };242 const req = agent.request(options, function (res) {243 let result = '';244 res.setEncoding('utf8');245 res.on('data', (chunk) => (result += chunk));246 res.on('end', () => resolve(JSON.parse(result)));247 });248 req.on('error', (err) => reject(err));249 req.end();250 });251}252function getChromiumRevision(gitRevision = null) {253 const fileName = 'src/revisions.ts';254 const command = gitRevision255 ? `git show ${gitRevision}:${fileName}`256 : `cat ${fileName}`;257 const result = execSync(command, {258 encoding: 'utf8',259 shell: true,260 });261 const m = result.match(/chromium: '(\d+)'/);262 if (!m) return null;263 return parseInt(m[1], 10);...

Full Screen

Full Screen

puppeteer.js

Source:puppeteer.js Github

copy

Full Screen

1const path = require('path');2const fs = require('fs');3const findNodeModules = require('find-node-modules');4const nodeModulePaths = findNodeModules({ relative: false });5const getFullPuppeteerPath = p => {6 return path.join(p, 'puppeteer');7};8const nodeModulePathWithPuppeteerConfig = nodeModulePaths.find(p => {9 const pathToTest = getFullPuppeteerPath(p);10 return fs.existsSync(pathToTest);11});12const puppeteerConfigPath = getFullPuppeteerPath(13 nodeModulePathWithPuppeteerConfig14);15module.exports = {16 getChromiumRevision: () => {17 let revision =18 process.env.PUPPETEER_CHROMIUM_REVISION ||19 process.env.npm_config_puppeteer_chromium_revision;20 if (!revision) {21 const revisionsFilePath = path.resolve(22 path.join(puppeteerConfigPath, 'lib/cjs/puppeteer/revisions.js')23 );24 if (fs.existsSync(revisionsFilePath)) {25 const revisionsFile = require(revisionsFilePath);26 if (27 revisionsFile.PUPPETEER_REVISIONS &&28 revisionsFile.PUPPETEER_REVISIONS.chromium29 ) {30 revision = revisionsFile.PUPPETEER_REVISIONS.chromium;31 } else {32 throw new Error(33 'Chromium revision is missing in revisions file of Puppeteer dependency'34 );35 }36 } else {37 // for older versions of Puppeteer38 const packageFile = require(path.resolve(39 path.join(puppeteerConfigPath, 'package.json')40 ));41 if (42 packageFile &&43 packageFile.puppeteer &&44 packageFile.puppeteer.chromium_revision45 ) {46 revision = packageFile.puppeteer.chromium_revision;47 } else {48 throw new Error(49 'Unable to find Chromium revision from Puppeteer. Ensure that you have Puppeteer installed.'50 );51 }52 }53 }54 return revision;55 }...

Full Screen

Full Screen

setup.js

Source:setup.js Github

copy

Full Screen

...36// jest-puppeteer to re-use this require from cache because at this point in time, we don't have the web socket written.37delete require.cache[path.resolve(process.env.JEST_PUPPETEER_CONFIG)];38module.exports = async jestConfig => {39 console.log('\n');40 const revision = getChromiumRevision();41 // set the version of Chromium to use based on Puppeteer42 await dockerSetChromiumConfig({43 revision,44 flags: chromiumFlags,45 downloadHost,46 useClosestUbuntuMirror47 });48 // launch Chromium in Docker ready for the first test suite49 const endpointPath = path.join(__dirname, '../', 'wsEndpoint');50 const webSocketUri = await dockerRunChromium();51 fs.writeFileSync(endpointPath, webSocketUri);52 await setupPuppeteer(jestConfig);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2(async () => {3 const browserFetcher = puppeteer.createBrowserFetcher();4 const revisionInfo = await browserFetcher.download('588429');5 console.log(revisionInfo.executablePath);6 console.log(revisionInfo.revision);7})();8Your name to display (optional):9Your name to display (optional):10const puppeteer = require('puppeteer');11(async () => {12 const browserFetcher = puppeteer.createBrowserFetcher();13 const revisionInfo = await browserFetcher.getChromiumRevision();14 console.log(revisionInfo);15})();16Your name to display (optional):

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2(async () => {3 const browserFetcher = puppeteer.createBrowserFetcher();4 const revisionInfo = await browserFetcher.download('588429');5 console.log(revisionInfo.revision);6})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2(async () => {3 const browserFetcher = puppeteer.createBrowserFetcher();4 const revisionInfo = await browserFetcher.download('591479');5 console.log(revisionInfo.revision);6 await browserFetcher.remove('591479');7})();8#### browser.newPage()9#### browser.pages()10#### browser.close()11#### browser.version()12#### browser.userAgent()13#### browser.process()14#### browser.target()15#### browser.wsEndpoint()16#### browser.isConnected()17#### browser.on(event, handler)18#### browser.once(event, handler)

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch({4 });5 const revision = browser.process().getChromiumRevision();6 console.log('Chromium revision: ' + revision);7 await browser.close();8})();9const puppeteer = require('puppeteer');10(async () => {11 const browser = await puppeteer.launch({12 });13 const revision = browser.process().getChromiumRevision();14 console.log('Chromium revision: ' + revision);15 await browser.close();16})();17const puppeteer = require('puppeteer');18(async () => {19 const browser = await puppeteer.launch({20 });21 const revision = browser.process().getChromiumRevision();22 console.log('Chromium revision: ' + revision);23 await browser.close();24})();25const puppeteer = require('puppeteer');26(async () => {27 const browser = await puppeteer.launch({28 });29 const revision = browser.process().getChromiumRevision();30 console.log('Chromium revision: ' + revision);31 await browser.close();32})();33const puppeteer = require('puppeteer');34(async () => {35 const browser = await puppeteer.launch({36 });37 const revision = browser.process().getChromiumRevision();38 console.log('Chromium revision: ' + revision);39 await browser.close();40})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2(async () => {3 const browserFetcher = puppeteer.createBrowserFetcher();4 const revisionInfo = browserFetcher.revisionInfo('588429');5 console.log(revisionInfo.revision);6 console.log(revisionInfo.folderPath);7 console.log(revisionInfo.executablePath);8 console.log(revisionInfo.url);9})();10const puppeteer = require('puppeteer');11(async () => {12 const browserFetcher = puppeteer.createBrowserFetcher();13 const revisionInfo = await browserFetcher.download('588429');14 console.log(revisionInfo.revision);15 console.log(revisionInfo.folderPath);16 console.log(revisionInfo.executablePath);17 console.log(revisionInfo.url);18})();19const puppeteer = require('puppeteer');20(async () => {

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2const browserFetcher = puppeteer.createBrowserFetcher();3const revisionInfo = browserFetcher.revisionInfo('533271');4console.log(revisionInfo);5const puppeteer = require('puppeteer');6const revisionInfo = puppeteer.getChromiumRevision();7console.log(revisionInfo);8const puppeteer = require('puppeteer');9const revisionInfo = puppeteer.getChromiumRevision();10console.log(revisionInfo);11const puppeteer = require('puppeteer');12const revisionInfo = puppeteer.getChromiumRevision();13console.log(revisionInfo);14const puppeteer = require('puppeteer');15const revisionInfo = puppeteer.getChromiumRevision();16console.log(revisionInfo);17const puppeteer = require('puppeteer');18const revisionInfo = puppeteer.getChromiumRevision();19console.log(revisionInfo);20const puppeteer = require('puppeteer');21const revisionInfo = puppeteer.getChromiumRevision();22console.log(revisionInfo);23const puppeteer = require('puppeteer');24const revisionInfo = puppeteer.getChromiumRevision();25console.log(revisionInfo);26const puppeteer = require('puppeteer');27const revisionInfo = puppeteer.getChromiumRevision();28console.log(revisionInfo);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Puppeteer automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful