Giter VIP home page Giter VIP logo

puppeteer-interceptor's People

Contributors

jsoverson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

puppeteer-interceptor's Issues

Please don't use atob on text data

I saw it had collapsed non-ascii characters originally encoded in utf-8.

For example, for ブーツ it produced ã��ã�¼ã��.

It'd be favorable to respect Content-Type in the response header.
Also, it'd be nice to pass the original base64 encoded data to event handlers that will bring a chance to solve this kind of problem by them.

Failed with auth proxies

Failing using auth proxies

var context = await browser.createIncognitoBrowserContext({ proxyServer: proxy });

await page.authenticate({
username: user,
password: pass,
})

Result: ERR_INVALID_AUTH_CREDENTIALS

The credentials are valid

Can't modify response headers

I want to modify response headers, but the codes below can't work.

intercept(page, patterns.Document('*'), {
    onInterception: event => {
      console.log(`${event.request.url} intercepted.`)
    },
    onResponseReceived: event => {
      event.response.headers.push({
        name: 'Link',
        value: '<https://x.xxx.com>; rel="preconnect"'
      });
      console.log(`${event.request.url} intercepted, going to modify`)
      return event.response;
    }
});

Besides, I try to modify the source code, use 'Fetch.continueRequest' to modify response headers, can't work either

// in my code
intercept(page, patterns.Document('*'), {
    onInterception: event => {
      console.log(`${event.request.url} intercepted.`)
    },
    onResponseReceived: event => {
      return null;
    }
});


// in source code
if (newResponse) {
    debug(`Fulfilling request ${requestId} with response returned from onResponseReceived`);
    console.log('newResponse headers count:', newResponse.headers.length);
    await client.send('Fetch.fulfillRequest', {
        requestId,
        responseCode: newResponse.statusCode,
        responseHeaders: newResponse.headers,
        body: newResponse.base64Body ? newResponse.base64Body : btoa_1.default(newResponse.body),
        responsePhrase: newResponse.statusMessage,
    });
}
else {
    // here I try to modify response headers
    await client.send('Fetch.continueRequest', { requestId, headers: [
        {name: 'Link', value: '<https://x.xxx.com>; rel="preconnect"'},
    ] });
}

Cant modify POST body in intercepted requests.

Simply logging the request object like so, it is clear that no field is exposed to modify a request POST body before it is sent out. This request here for example does have a POST body, but it is not indicated here, and cannot be mutated in any way.

console.log(event.request);

{
  url: 'https://someurl',
  method: 'GET',
  headers: {
    'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90"',
    'sec-ch-ua-mobile': '?0',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4403.0 Safari/537.36',
    Accept: '*/*'
  },
  initialPriority: 'Low',
  referrerPolicy: 'strict-origin-when-cross-origin'
}

302 redirected not response body --->throw Can only get response body on requests captured after headers received.

302 redirect not have response body,throw Error "Can only get response body on requests captured after headers received"
Maybe you need a ---> try catch

try {
    const responseCdp = (await client.send('Fetch.getResponseBody', {
        requestId,
    }));
    const response = {
        body: responseCdp.base64Encoded ? atob_1.default(responseCdp.body) : responseCdp.body,
        headers: event.responseHeaders,
        errorReason: event.responseErrorReason,
        statusCode: event.responseStatusCode,
    };
    newResponse = await this.eventHandlers.onResponseReceived({ response, request });
} catch (e) {
    console.log(e);
    newResponse = await this.eventHandlers.onResponseReceived({ test: 'test' });
}

Does not allow page.authenticate({})

Does not allow proxies with authentication to be authenticated.

const proxyUser = `o`;
const proxyPass = 'f';
const options = {
  headless: false,
  // devtools: true,
  args: [
    '--no-sandbox',
    `--proxy-server=proxy:22225`,
  ],
};
let browser = await puppeteer.launch(options);
const page = await browser.newPage();

await page.authenticate({ username: proxyUser, password: proxyPass });

await page.goto('chrome://about')

Rather than authenticate the page it will ask for authentication.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.