Skip to content

Commit

Permalink
Add helper script that runs chromium.
Browse files Browse the repository at this point in the history
The feature that we were previously using in chromium_headless v110 and
earlier seems to have been removed in v111. This changes the code
to use puppeteer-core to interact with chromium.

This change is intended to be a drop in replacement: The portal_settings
config that specifies the path to chromium is still used and we package the
puppeteer code so no need for post install steps.
  • Loading branch information
jpwhite4 committed Mar 23, 2023
1 parent 6865639 commit 4fdac2c
Show file tree
Hide file tree
Showing 9 changed files with 1,280 additions and 28 deletions.
14 changes: 14 additions & 0 deletions background_scripts/chrome-helper/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"env": {
"node": true
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
"no-console": "off"
},
"globals": {
"document": "readonly"
}
}
28 changes: 28 additions & 0 deletions background_scripts/chrome-helper/chrome-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env node
const puppeteer = require('puppeteer-core');
const args = require('yargs').argv;

(async () => {
const browser = await puppeteer.launch({
executablePath: args['path-to-chrome'],
args: ['--no-sandbox', '--disable-extensions', '--disable-setuid-sandbox']
});
const page = await browser.newPage();

if (args['window-size']) {
let dimensions = args['window-size'].split(',');
await page.setViewport({
width: parseInt(dimensions[0], 10),
height: parseInt(dimensions[1], 10),
deviceScaleFactor: 1
});
}

await page.goto('file://' + args['input-file']);

const innerHtml = await page.evaluate(() => document.querySelector('.highcharts-container').innerHTML);

console.log(JSON.stringify(innerHtml));

await browser.close();
})();
Loading

0 comments on commit 4fdac2c

Please sign in to comment.