Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return (window: DOMWindow) => {
const mutationObserverPolyfill = readFile(require.resolve('mutationobserver-shim'));
const customElementsPolyfill = readFile(path.join(__dirname, 'polyfills', 'custom-elements.min.js'));
const mutationScript: vm.Script = new vm.Script(mutationObserverPolyfill);
const customElementsScript: vm.Script = new vm.Script(customElementsPolyfill);
mutationScript.runInContext(jsdomutils.implForWrapper(window.document)._global);
customElementsScript.runInContext(jsdomutils.implForWrapper(window.document)._global);
window.document.domain = new URL(finalHref).host;
/* istanbul ignore next */
window.matchMedia = () => {
return { addListener() { } } as any;
};
Object.defineProperty(window.HTMLHtmlElement.prototype, 'clientWidth', { value: 1024 });
Object.defineProperty(window.HTMLHtmlElement.prototype, 'clientHeight', { value: 768 });
};
};
set: function(type) {
// Allow replacement of internal node-canvas, so we can switch to a
// PDF canvas.
var impl = idlUtils.implForWrapper(this),
size = impl._canvas || impl;
impl._canvas = new Canvas(size.width, size.height, type);
impl._context = null;
}
});
set: function(type) {
// Allow replacement of internal node-canvas, so we can switch to a
// PDF canvas.
var impl = idlUtils.implForWrapper(this),
size = impl._canvas || impl;
impl._canvas = new Canvas(size.width, size.height, type);
impl._context = null;
}
});
HTMLCanvasElement.prototype[key] = function() {
var canvas = idlUtils.implForWrapper(this)._canvas;
return canvas[key].apply(canvas, arguments);
};
});
return setTimeout(async () => {
try {
const script: vm.Script = new vm.Script(source);
const evaluteResult = await script.runInContext(jsdomutils.implForWrapper(jsdom.window.document)._global);
result.evaluate = evaluteResult;
} catch (err) {
result.error = err;
}
process.send!(result);
}, waitFor);
};
HTMLCanvasElement.prototype[key] = function() {
var canvas = idlUtils.implForWrapper(this)._canvas;
return canvas[key].apply(canvas, arguments);
};
});