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

Cloud Insights Browser Audits PoC #1400

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Blinkuu
Copy link

@Blinkuu Blinkuu commented Jul 18, 2024

What?

This is a little PoC showcasing the possibility of enabling CDP's Audits domain and listening to associated issues for every page.

To see it work:

make build
./xk6-browser run -v examples/pagegoto.js 2>&1 | grep -E "Audits|onIssueAdded" > logs.log
cat logs.log

Warning: This PoC is not intended to be merged, at least in its current form and status.

Why?

N/A

Checklist

  • I have performed a self-review of my code
  • I have added tests for my changes
  • I have commented on my code, particularly in hard-to-understand areas

Related PR(s)/Issue(s)

@Blinkuu Blinkuu self-assigned this Jul 18, 2024
@@ -3,7 +3,7 @@ module github.com/grafana/xk6-browser
go 1.20

require (
github.com/chromedp/cdproto v0.0.0-20221023212508-67ada9507fb2
github.com/chromedp/cdproto v0.0.0-20240709201219-e202069cc16b
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to update the chromedp package as it didn't have the newest CDP protocol's type definitions and Audits.issueAdded events failed to unmarshal in session.go:

ev, err := cdproto.UnmarshalMessage(msg)
if errors.Is(err, cdp.ErrUnknownCommandOrEvent("")) && msg.Method == "" {
// Results from commands may not always have methods in them.
// This is the reason of this error. So it's harmless.
//
// Also:
// This is most likely an event received from an older
// Chrome which a newer cdproto doesn't have, as it is
// deprecated. Ignore that error, and emit raw cdproto.Message.
s.emit("", msg)
continue
}
if err != nil {
s.logger.Debugf("Session:readLoop:<-s.readCh", "sid:%v tid:%v cannot unmarshal: %v", s.id, s.targetID, err)
continue
}
s.emit(string(msg.Method), ev)

I simply updated to the newest version:

go get -u github.com/chromedp/chromedp

@Blinkuu Blinkuu requested a review from inancgumus July 18, 2024 13:07
Comment on lines +115 to +121
postData: func(ents []*network.PostDataEntry) string {
var b bytes.Buffer
for _, e := range ents {
b.WriteString(e.Bytes)
}
return b.String()
}(ev.Request.PostDataEntries),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new cdproto version removed the already deprecated PostData field on network.Request. Actually supporting the new protocol format could take some time. Not sure what this is used for and how hard it'd be upgrade at this point 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, updating cdproto is fine for this PoC. However, updating cdproto has some issues (as seen here) in general. We can do the update in a separate PR before this one so that we can ensure that the browser module is still stable after the update.

@inancgumus inancgumus removed their request for review September 19, 2024 02:28
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