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

Add web vital metrics #836

Merged
merged 19 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions common/browser_context.go
Copy link
Member

Choose a reason for hiding this comment

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

The downside is that we will need to manually update this library, and users who do not update to latest k6 binary will be working with an outdated version of the library.

It's better to fixate on a single version rather than breaking our code when the original webvital js lib gets updated. So, to me, it's an upside :)

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/grafana/xk6-browser/api"
"github.com/grafana/xk6-browser/common/js"
"github.com/grafana/xk6-browser/k6error"
"github.com/grafana/xk6-browser/k6ext"
"github.com/grafana/xk6-browser/log"
Expand Down Expand Up @@ -64,6 +65,8 @@ func NewBrowserContext(
b.GrantPermissions(opts.Permissions, nil)
}

b.evaluateOnNewDocumentSources = append(b.evaluateOnNewDocumentSources, js.WebVitalIIFEScript)

return &b
}

Expand Down
12 changes: 12 additions & 0 deletions common/js/web_vital.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package js

import (
_ "embed"
)

// WebVitalIIFEScript was downloaded from
// https://unpkg.com/web-vitals@3/dist/web-vitals.iife.js.
// Repo: https://github.com/GoogleChrome/web-vitals
//
//go:embed web_vital_iife.js
var WebVitalIIFEScript string
1 change: 1 addition & 0 deletions common/js/web_vital_iife.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.