is cross policy an issue with puppeteer 2f headless chrome 3f

Solutions on MaxInterview for is cross policy an issue with puppeteer 2f headless chrome 3f by the best coders in the world

showing results for - "is cross policy an issue with puppeteer 2f headless chrome 3f"
Abril
31 Jan 2018
1const fetch = require('node-fetch')
2
3const requestInterceptor = async (request) => {
4  try {
5    const url = request.url()
6    const requestHeaders = request.headers()
7    const acceptHeader = requestHeaders.accept || ''
8    if (url.includes("example.com") && (acceptHeader.includes('text/html'))) {
9      const cookiesList = await page.cookies(url)
10      const cookies = cookiesList.map(cookie => `${cookie.name}=${cookie.value}`).join('; ')
11      delete requestHeaders['x-devtools-emulate-network-conditions-client-id']
12      if (requestHeaders.Cookie) {
13        requestHeaders.cookie = requestHeaders.Cookie
14        delete requestHeaders.Cookie
15      }
16      const theseHeaders = Object.assign({'cookie': cookies}, requestHeaders, {'accept-language': 'en-US,en'})
17
18      const init = {
19        body: request.postData(),
20        headers: theseHeaders,
21        method: request.method(),
22        follow: 20,
23      }
24      const result = await fetch(
25        url,
26        init,
27      )
28      const resultHeaders = {}
29      result.headers.forEach((value, name) => {
30        if (name.toLowerCase() !== 'content-security-policy') {
31          resultHeaders[name] = value
32        } else {
33          console.log('CSP', `omitting CSP`, {originalCSP: value})
34        }
35      })
36      const buffer = await result.buffer()
37      await request.respond({
38        body: buffer,
39        resultHeaders,
40        status: result.status,
41      })
42    } else {
43      request.continue();
44    }
45  } catch (e) {
46    console.log("Error while disabling CSP", e);
47    request.abort();
48  }
49}
50
51await page.setRequestInterception(true)
52page.on('request', requestInterceptor)
53