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

Breakpoints #1555

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft

Breakpoints #1555

wants to merge 13 commits into from

Conversation

inancgumus
Copy link
Member

@inancgumus inancgumus commented Dec 2, 2024

This PR contains experimental features to debug a k6-browser script.

Breakpoint client

This PR adds the ability to pause script execution from the given breakpoints and resume them.

The client pauses the script execution when a breakpoint is hit.

Protocol

command explanation
get_breakpoints Client initially requests the breakpoints from the server.
update_breakpoints Client continuously listens for new breakpoints from the server.
resume Server can resume the script execution.

get_breakpoints

The client waits for the server to send an initial set of breakpoints before continuing. The reason for "handshaking" an initial breakpoint is to pause the script execution until the server responds with something. Otherwise, the script would immediately continue.

Client

{
    "command": "get_breakpoints"
}

Server

[
    {
        "file": "file:///Users/inanc/grafana/k6browser/main/examples/fillform.js",
        "line": 28
    }
]

update_breakpoints

Server

{
    "command": "update_breakpoints",
    "data": [
        {
            "file": "file:///Users/inanc/grafana/k6browser/main/examples/fillform.js",
            "line": 30
        }
    ]
}

resume

Server

{
    "command": "resume"
}

Activate the client

K6_BROWSER_BREAKPOINT_SERVER_URL=ws://localhost:8080/breakpoint k6 run script.js

Open a DevTools window

For convenience, users may open a DevTools window.

K6_BROWSER_DEBUG=1 k6 ...

Usage:
K6_BROWSER_DEBUG=1 K6_BROWSER_HEADLESS=0 ...

Note: Automatically disables headless to work with the DevTools window.

Bug: fillform.js loses the DevTools window when it gets redirected to an
unauthorized page. It's probably due to the redirect.
@inancgumus inancgumus changed the title Open devtools when DEBUG=1 is given Breakpoints Dec 3, 2024
@inancgumus inancgumus force-pushed the add/debugger-breakpoint branch 2 times, most recently from ef68a20 to aeb52a5 Compare December 3, 2024 16:09
- We can't ask for the breakpoints, VSCode pushes them when they're
  available or when the debugger starts.
- We need to retrieve the breakpoint details, as well as the column and
  funcName. These are passed to VSCode when the process is paused.
- The sendPause method on the client needs to be called from pause so
  that VSCode updates the GUI to show where it has paused and to allow
for the resume button to be made visible.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants