facebook/memlab

How to set PuppeteerConfig correctly?

HazTheGoat opened this issue · 6 comments

Issue Title:

Cannot get browserInfo.setPuppeteerConfig to work

Description:

I have a website that uses Azure b2c login and I want puppeteer to use my standard/default browser for testing when setting --headful flag instead of using Chromium (or whatever the correct name is for the "Chrome for testing" browser name is). I have tried using the browserInfo.setPuppeteerConfig from @memlab/core package, but cannot get it to work.

Expected Behavior:

Expect it to use my standard Chrome as browser for "test"

Actual Behavior:

Still uses the default Chromium browser as if I haven't set any browserInfo.setPuppeteerConfig

Below is my entire scenario.js file


const { setTimeout } = require("timers/promises")
const { browserInfo } = require("@memlab/core")
const cookieValue = `MyCookieValue`

browserInfo.setPuppeteerConfig({
    executablePath:
        "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",
    channel: "chrome",
    devtools: true,
})

const scenario = {
    url: () => {
        return "http://localhost:4200/"
    },
    action: async page => {
        setTimeout(() => {}, 150000)
    },
    back: async page => {
        setTimeout(() => {}, 150000)
    },
    cookies: () => [
        {
            name: ".AspNet.SharedCookie.Api.Test",
            value: cookieValue,
            domain: "localhost",
        },
        {
            name: ".AspNet.SharedCookie.Api.Test",
            value: cookieValue,
            domain: ".api.test.miros.app",
        },
    ],
}

module.exports = scenario


browserInfo is mainly used for logging browser runtime information. The setPuppeteerConfig is an internal API used by MemLab core to set the puppeteer information used by the logger.

If you would like to set the executable binary of the browser, consider using the --chromium-binary CLI argument:

memlab run --scenario scenario.js --chromium-binary <path to Chrome binary>

Thank you for the quick reply. I tried your suggestion and this did actually make memlab use my normal chrome instead of chromium, but there is still one issue. I would expect the chrome instance to keep me logged in to my website, but it doesn't. In fact, it looks like a clean version of chrome where I'm not logged in and no addons are installed etc. I expected this to use my "normal" chrome.

Here is the exact command I used:
memlab run --scenario .\libs\shared\memlab\scenario.js --headful --chromium-binary "C:\Program Files\Google\Chrome\Application\chrome.exe"

To have chrome logged in, you can define the cookies callback in the scenario file:
https://facebook.github.io/memlab/docs/api/interfaces/core_src.IScenario/#optional-cookies

In the example code I provided the cookies callback is set. I can confirm that I see the cookies applied correctly by looking at my Devtools > Application > Cookies. The name and value is set correctly. The only difference I see between the cookies is that my normal chrome instance has HttpOnly set to true, Secure set to true and SameSite set to None, whereas the memlab instance of chrome doesn't have a value set for any of the above mentioned properties. I can add some screenshots to compare the two cookies.

memlab instance of chrome
image

normal instance of chrome
image

Do you know of a way for me to set those properties to match my normal chrome version of cookies?

Can you try adding httpOnly: true to the argument passed to the cookies callback?

const scenario = {
  ...
  cookies: () => [
    {name:'cookie_name', value: 'cookie_value', httpOnly: true, domain: ...},
    ...
  ],
};

This actually worked! I never thought to try this because of the documentation for the Cookies type defined here
https://github.com/facebook/memlab/blob/fdac330/packages/core/src/lib/Types.ts#L189