Files
image-sequencer/src/modules/_nomodule/gl-context.js
Rishabh Shukla 287d7e2be1 fix blob analysis to work in node (#1589)
Co-authored-by: h <f>
Co-authored-by: Harsh Khandeparkar <34770591+HarshKhandeparkar@users.noreply.github.com>
Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>
2022-01-25 18:05:32 -05:00

40 lines
1.6 KiB
JavaScript

module.exports = function runInBrowserContext(input, callback, step, options) {
// to ignore this from getting browserified
const puppeteer = eval('require')('puppeteer');
//Stripped down version of options which is serializable
var minOptions = require('lodash').cloneDeep(options);
minOptions.step = options.step.name;
var obj = { input: input, modOptions: minOptions };
puppeteer.launch({headless: true, args:['--no-sandbox', '--disable-setuid-sandbox']}).then(function(browser) {
browser.newPage().then(page => {
/* Maybe there is a better way to this, loading the page coz localstorage API
is not available otherwise */
page.goto('https://google.com').then(() => {
page.addScriptTag({ path: require('path').join(__dirname, '../../../dist/image-sequencer.js') }).then(() => {
page.addScriptTag({path: require('path').join(__dirname, '../../../node_modules/opencv.js/opencv.js')}).then(() => {
page.evaluate((options) => {
return new Promise((resolve, reject) => {
var sequencer = ImageSequencer();
sequencer.loadImage(options.input.src);
sequencer.addSteps(options.modOptions.step, options.modOptions);
sequencer.run(function cb(out) {
resolve(sequencer.steps[1].output.src);
});
});
}, obj).then(el => {
browser.close().then(() => {
step.output = { src: el, format: input.format };
callback();
});
});
});
});
});
});
});
};