-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Browser: add route.fulfill #4961
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
base: agnestoulet/poc-page-route
Are you sure you want to change the base?
Browser: add route.fulfill #4961
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work, despite it being your first PRs 🙇. I've posted some suggestions. We should also fix the linter errors.
@@ -0,0 +1,73 @@ | |||
package common |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this refactoring. I'd keep all HTTP-related code in http.go
as before, as I don't mind about the file line length. No strong opinion, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll revert this change! Now that I think again about this, I think it makes sense to keep it in http.go
. And if the file size becomes an issue, it would probably make more sense to split it into three to have response.go
, request.go
and route.go
. Reverted in 2e31eae
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️ In that case, I'd suggest http_response.go
, http_request.go
, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job @AgnesToulet 👏🏻 Nothing stood out to me, besides what @inancgumus mentioned, so I'll wait on his further review comments to 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Looks good. Just a couple of things to consider first before we can merge this in.
route.Continue() | ||
|
||
if err := route.Continue(); err != nil { | ||
m.logger.Warnf("FrameManager:requestStarted", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also be an error log, like it is in onRequestPaused?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the other one better be a warning to reduce log clutter.
|
||
action := fetch.FulfillRequest(request.interceptionID, responseCode) | ||
|
||
if opts.ContentType != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still need to check for nil
opts
? Maybe we need to check for nil
opts at the beginning and fulfill
with no extra options? Otherwise adding the options fields that aren't nil
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for parseFulfillOptions
to return a pointer: *common.FulfillOption
? If not, we could just return a zero-value FulfillOption
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you're right, I fixed it in the following PR but can do it here (I'm focusing on merging page.route first, then update this PR with your feedback). I'll look into removing the pointer as well.
What?
This PR adds the
route.fulfill
function. Used inpage.route
, it allows to fulfill a request with a given response.Why?
This helps with Playwright compatibility and allow to mock requests while testing.
Checklist
make check
) and all pass.Checklist: Documentation (only for k6 maintainers and if relevant)
Please do not merge this PR until the following items are filled out.
Related PR(s)/Issue(s)
Part of #4502
Known limitation
As you can see in the test script below, if you want to fulfill a request to an external website you need to handle CORS yourself. Playwright had the same issue described here with multiple proposed solution. They fixed it by adding CORS for external request if no overrides are provided: see this function. I tried to do the same but struggled with the request origin not being set on our side. I don't think it's blocking this PR though but I'd like to know your thoughts about this issue, if we should try to follow Playwright or choose another option (document it or allow it if an option is set).
Test script
To test the full workflow, I'm using the following k6 script. It's not part of the PR because it depends on a change on quickpizza: grafana/quickpizza#225 but you can play with it if you run QuickPizza locally.