question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Cannot remove header in `route.continue`

See original GitHub issue

Context:

  • Playwright Version: 1.20.1
  • Operating System: Linux
  • Node.js version: 17.8.0
  • Browser: Chromium

Code Snippet

const playwright = require('playwright');

require('http').createServer((request, response) => {
        response.end('');
}).listen(8888);

(async () => {
        const browser = await playwright.chromium.launchPersistentContext('', {
                headless: false,
        });

        const page = await browser.newPage();

        await page.route('**/*', (route, request) => {
          // Override headers
          const headers = {
            ...request.headers(),
            foo: 'bar', // set "foo" header
            origin: undefined, // remove "origin" header
          };
          route.continue({headers});
        });

        await page.goto('http://localhost:8888/', { waitUntil: 'load' });
})();

Describe the bug

The example https://playwright.dev/docs/next/api/class-route#route-continue is broken.

node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

route.continue: headers[7].value: expected string, got undefined
    at RouteHandler.handler (/home/szm/Desktop/cache/bug6.js:21:18)

Node.js v17.8.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
yury-scommented, May 3, 2022

Thanks for confirming. Setting to undefined should now delete headers. I looked at WebKit implementation and there is no simple way to make it remove/update origin header, I’ve filed a separate issue for that (https://github.com/microsoft/playwright/issues/13886) and will wait until there is more demand for this before implementing any suboptimal solutions.

1reaction
rwollcommented, Mar 28, 2022

Thanks for the report! I repro’d locally.

Does using delete built-in before passing along the headers work for your use case?

const headers = {
  ...request.headers(),
  foo: 'bar'
};

delete headers['x-some-header'];
…

Regardless, we’ll either update the docs or make the doc example work!


Note from repro: The error is likely from our protocol type def: https://github.com/microsoft/playwright/blob/1471bb71776cf84223190e1552ee4e055db1547a/packages/playwright-core/src/protocol/protocol.yml#L2442

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't Delete Header and Footer - Microsoft Community
I want to delete the header and footer from my Word document but it doesn't seem to want to leave. I click on...
Read more >
Cannot remove headers after they are sent to the client - Stack ...
You get this error because you are calling res.send() multiple times: router.get('/hello', async function(req, res, next) { const allData ...
Read more >
Sections / Headers and Footers in Microsoft Word
REMINDER: If you have multiple Sections in a document and a Section's header/footer is set for link to previous, that will continue not...
Read more >
Adding custom headers to origin requests - Amazon CloudFront
Use an origin request policy that forwards all viewer headers to the origin. You cannot forward the Authorization header individually in an origin...
Read more >
Exception Clause - Apache Camel
So the caller receives an Exchange with the payload Order ERROR and a orderid=failed in a header. Using Handled with Spring XML DSL....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found