lib/grover/js/processor.js in grover-0.14.2 vs lib/grover/js/processor.js in grover-1.0.0

- old
+ new

@@ -64,16 +64,68 @@ const timeout = options.timeout; delete options.timeout; if (timeout !== undefined) { requestOptions.timeout = timeout; } + // Setup user agent (if provided) + const userAgent = options.userAgent; delete options.userAgent; + if (userAgent !== undefined) { + await page.setUserAgent(userAgent); + } + // Setup viewport options (if provided) const viewport = options.viewport; delete options.viewport; if (viewport !== undefined) { await page.setViewport(viewport); } + // If specified, emulate the media type + const emulateMedia = options.emulateMedia; delete options.emulateMedia; + if (emulateMedia !== undefined) { + if (typeof page.emulateMediaType === 'function') { + await page.emulateMediaType(emulateMedia); + } else { + await page.emulateMedia(emulateMedia); + } + } + + // Emulate the media features, if specified + const mediaFeatures = options.mediaFeatures; delete options.mediaFeatures; + if (Array.isArray(mediaFeatures)) { + page.emulateMediaFeatures(mediaFeatures); + } + + // Emulate timezone (if provided) + const timezone = options.timezone; delete options.timezone; + if (timezone !== undefined) { + await page.emulateTimezone(timezone); + } + + // Emulate vision deficiency (if provided) + const visionDeficiency = options.visionDeficiency; delete options.visionDeficiency; + if (visionDeficiency !== undefined) { + page.emulateVisionDeficiency(type); + } + + // Bypass CSP (content security policy), if provided + const bypassCSP = options.bypassCSP; delete options.bypassCSP; + if (bypassCSP !== undefined) { + page.setBypassCSP(bypassCSP); + } + + // Add extra HTTP headers (if provided) + const extraHTTPHeaders = options.extraHTTPHeaders; delete options.extraHTTPHeaders; + if (extraHTTPHeaders !== undefined) { + page.setExtraHTTPHeaders(extraHTTPHeaders); + } + + // Set geolocation (if provided) + const geolocation = options.geolocation; delete options.geolocation; + if (geolocation !== undefined) { + page.setGeolocation(geolocation); + } + const waitUntil = options.waitUntil; delete options.waitUntil; if (urlOrHtml.match(/^http/i)) { // Request is for a URL, so request it requestOptions.waitUntil = waitUntil || 'networkidle2'; await page.goto(urlOrHtml, requestOptions); @@ -89,20 +141,10 @@ }); const displayUrl = options.displayUrl; delete options.displayUrl; await page.goto(displayUrl || 'http://example.com', requestOptions); } - // If specified, emulate the media type - const emulateMedia = options.emulateMedia; delete options.emulateMedia; - if (emulateMedia !== undefined) { - if (typeof page.emulateMediaType == 'function') { - await page.emulateMediaType(emulateMedia); - } else { - await page.emulateMedia(emulateMedia); - } - } - // add styles (if provided) const styleTagOptions = options.styleTagOptions; delete options.styleTagOptions; if (Array.isArray(styleTagOptions)) { for (const styleTagOption of styleTagOptions) { await page.addStyleTag(styleTagOption); @@ -125,10 +167,28 @@ // If specified, wait for selector const waitForSelector = options.waitForSelector; delete options.waitForSelector; const waitForSelectorOptions = options.waitForSelectorOptions; delete options.waitForSelectorOptions; if (waitForSelector !== undefined) { - await page.waitForSelector(waitForSelector, waitForSelectorOptions) + await page.waitForSelector(waitForSelector, waitForSelectorOptions); + } + + // If specified, wait for timeout + const waitForTimeout = options.waitForTimeout; delete options.waitForTimeout; + if (waitForTimeout !== undefined) { + await page.waitForTimeout(waitForTimeout); + } + + // If specified, focus on the specified selector + const focusSelector = options.focus; delete options.focus; + if (focusSelector !== undefined) { + await page.focus(focusSelector); + } + + // If specified, hover on the specified selector + const hoverSelector = options.hover; delete options.hover; + if (hoverSelector !== undefined) { + await page.hover(hoverSelector); } // If we're running puppeteer in headless mode, return the converted PDF if (debug === undefined || (typeof debug === 'object' && (debug.headless === undefined || debug.headless))) { return await page[convertAction](options);