Skip to content

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

@uriya2

Description

@uriya2

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@email.com");
        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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions