Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Can't add 'set-cookie' headers via page.route fulfill? #4842

Closed
uriya2 opened this issue Dec 29, 2020 · 4 comments
Closed

[Question] Can't add 'set-cookie' headers via page.route fulfill? #4842

uriya2 opened this issue Dec 29, 2020 · 4 comments

Comments

@uriya2
Copy link

uriya2 commented Dec 29, 2020

Context:

  • Playwright Version: ^1.7.0

  • Operating System: Ubuntu 16.04.4 LTS

  • Node.js version: v12.18.1

  • Browser: Chromium

Code Snippet

const playwright = require("playwright");

(async () => {
    for (const browserType of ['chromium']) {
        /** @type {import('playwright').Browser} */
        const browser = await playwright['chromium'].launch({ headless: false });
        const context = await browser.newContext();
        const page = await context.newPage();

        page.route('**/*', (route, request) => {
            let requestUrl = request.url();
            if (requestUrl.indexOf("sleeknote.com/Login/Login")>-1){
                let mockedResp = {
                    status: 200,
                    contentType: "application/json; charset=utf-8",
                    body: null,
                    headers:
                        {
                            "Access-Control-Allow-Credential": true,
                            "Access-Control-Allow-Headers": "Origin, Content-Type, X-Auth-Token",
                            "Access-Control-Allow-Methods": "GET, POST, PATCH, PUT, DELETE, OPTIONS",
                            "Access-Control-Allow-Origin": "*",
                            "Cache-Control": "private",
                            "Connection": "keep-alive",
                            "Content-Length": 9,
                            "Content-Type": "application/json; charset=utf-8",
                            "Set-Cookie": "A1",
                            "X-AspNet-Version": "4.0.30319",
                            "X-AspNetMvc-Version": "4.0",
                            "X-Powered-By": "ASP.NET"
                        }
                };
                route.fulfill(mockedResp)
            }else{
                route.continue();
            }
        })
        await page.goto('https://dashboard.sleeknote.com/login');
        await page.fill("#email", "[email protected]");
        await page.fill("#password", "q1w2e3r4");
        await page.click('[type="submit"]');
        await browser.close();
    }
})();

Describe the bug
hi,

As I'm trying to add multiple 'set-cookie' to the response header I noticed that even 1 'set-cookie' wasn't added. The rest of the headers are added just fine.
Also, any idea on how to add multiple headers to a response?

@mxschmitt
Copy link
Member

Hi, good catch, seems definitely a valid use-case and from my point of view not yet possible. An array should be probably be accepted in the k/v pair too which then allows to set a header multiple times.

@pavelfeldman
Copy link
Member

Any particular reason you are not using https://playwright.dev/docs/next/api/class-browsercontext#browsercontextaddcookiescookies? I acknowledge the bug, but figuring out why you hit it at the first place.

@uriya2
Copy link
Author

uriya2 commented Jan 17, 2021

@pavelfeldman Good question, I will check it as a workaround for these type of cookie, I wonder if it will work as I assume the login response is being consumed and executed to asses if a login action should be fired. Might be that setting those cookies won't have the desired affect. Will check none the less.

@dgozman
Copy link
Contributor

dgozman commented Feb 19, 2021

Same issue as #4987.

@dgozman dgozman closed this as completed Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants