playwright-community / playwright-go

Playwright for Go a browser automation library to control Chromium, Firefox and WebKit with a single API.
https://playwright-community.github.io/playwright-go/
MIT License
1.94k stars 144 forks source link

fix: prevent misuse of transformOptions #389

Closed canstand closed 8 months ago

canstand commented 8 months ago

transformOptions was previously restricted and does not report misuse.

Now no longer restricted, and it is more intuitive to take overrides as the second argument when calling it.

Lonka commented 7 months ago

Hi,

I have a little question about how to fix this issue. I understand the playwright is based on the DevTools Protocol to control or monitor the test actions from browser.

So I think the CDP must has the screenshop interface, it's correctly for this link. captureScreenshot

But the screenshot properties of playwright-go provides is a bit different from CDP, such as Timeout, OmitBackground, etc. PageScreenshotOptions

As mentioned above, I think the channel.Send command that are changed more times as this request, is NOT sent to CDP directly. It's maybe send to the playwright service which running on the nodejs. But in the playwright opensource, I could not find where to receive the commands from the playwright-go.

I would like to learn the channel.Send command is wrappered args to what payload(JSON?), and send to where? and where to receive this command. If it is possible may I know the received code in where? thanks.

canstand commented 7 months ago

playwright-go communicates with playwright server cli via stdin/out, see

https://github.com/playwright-community/playwright-go/blob/ddc7abdd06db016d63664de1ab08870195085ddb/run.go#L208

Protocol reference

mxschmitt commented 7 months ago

Playwright for Go (client) -> Playwright driver (server) -> CDP

Lonka commented 7 months ago

Hi all,

Thank you for protocol reference link and data flow describe, which helped me understood how the playwright-go to call the CDP throught playwright driver.

In playwright-go, write the message via stdin/out as @canstand said. https://github.com/playwright-community/playwright-go/blob/ddc7abdd06db016d63664de1ab08870195085ddb/transport.go#L75-L80

The message is formattd as JSON, like as below:

{
    "guid": "page@062788f754dd92af98243a1c957eb01a",
    "id": 22,
    "metadata":
    {
        "apiName": "SerializeCallStack",
        "isInternal": false,
        "location":
        {
            "file": "connection.go",
            "line": 152
        },
        "wallTime": 191577195
    },
    "method": "screenshot",
    "params":
    {
        "mask":
        [
            {
                "frame":
                {
                    "guid": "frame@c1bdcb321ef5827508f483b621232c6e"
                },
                "selector": "//*[@id=\"btnLogin\"]"
            }
        ],
        "maskColor": "rgba(255,0,255,0.5)"
    }
}

And the code of the playwright driver to receive the message as below: https://github.com/microsoft/playwright/blob/19b0f5ccb38fb0dee6e04b44448a8a2a212ee393/packages/playwright-core/src/cli/driver.ts#L39C1-L41

The stdin/out protocol must reference cli protocol.

Thanks again.