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

Error when parsing null remote object #793

Closed
ka3de opened this issue Feb 24, 2023 · 3 comments · Fixed by #859
Closed

Error when parsing null remote object #793

ka3de opened this issue Feb 24, 2023 · 3 comments · Fixed by #859
Assignees
Labels
bug Something isn't working user request Requested by the community
Milestone

Comments

@ka3de
Copy link
Collaborator

ka3de commented Feb 24, 2023

Brief summary

There is a mishandling of RemoteObject parsing when this one is of subtype null. This mishandling ends up on our implementation trying to unmarshal a nil value which ultimately results in a panic with error:

panic: GoError: parsing remote object value: unexpected end of JSON input

The concrete flow is the following:

  • parseRemoteObject method is called with a cdpruntime.RemoteObject with subtype null and obj.UnserializableValue = ""
    See example of received data:
runtime.RemoteObject{Type:"object", Subtype:"null", ClassName:"", Value:easyjson.RawMessage(nil), UnserializableValue:"", Description:"", WebDriverValue:(*runtime.WebDriverValue)(nil), ObjectID:"", Preview:(*runtime.ObjectPreview)(nil), CustomPreview:(*runtime.CustomPreview)(nil)}
  • Becuase UnserializableValue = "" the call is made to parseRemoteObjectValue.
  • We end up in the switch case for TypeObject, but because ObjectPreview is nil and val != Object, execution goes to the end of the function, where the value (nil in this case) will be attempted to be serialized, resulting the mentioned error.

Solution
We should add an explicit case inside TypeObject case in order to handle nullsubtype.

See the CDP specs for remote object and possible values for type and subtype.

xk6-browser version

v0.8.1

OS

Ubuntu 20.04.5 LTS

Chrome version

109.0.5414.119 (Official Build) (64-bit)

Docker version and image (if applicable)

No response

Steps to reproduce the problem

The problem can be reproduced with this script:

import { chromium } from 'k6/x/browser';

export default function () {
  const browser = chromium.launch({ headless: false/*, debug: true*/ });
  const page = browser.newPage();

  page
    .goto('https://apply.mykaleidoscope.com/')
    .then(() => {
        console.log("navigated");
    })
    .finally(() => {
      page.close();
      browser.close();
    });
}

Expected behaviour

The xk6-browser execution finishes correctly, navigating to the website.

Actual behaviour

The execution crashes with the following error:

scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
           * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

WARN[0001] "Google Maps JavaScript API has been loaded directly without a callback. This is not supported and can lead to race conditions and suboptimal performance. For supported loading patterns please see https://goo.gle/js-api-loading"  source=browser-console-api
WARN[0001] url:https://js.stripe.com/v3/m-outer-93afeeb17bc37e711759584dbfc50d47.html method:GET err:fetching response body: No resource with given identifier found (-32000)  category="Response:bodySize:fetchBody" elapsed="0 ms" goroutine=386
WARN[0001] url:https://js.stripe.com/v3/fingerprinted/js/m-outer-8cb24ab2d649fd36a488d04d8c457933.js method:GET err:fetching response body: No resource with given identifier found (-32000)  category="Response:bodySize:fetchBody" elapsed="0 ms" goroutine=386
WARN[0001] url:https://m.stripe.network/inner.html method:GET err:fetching response body: No resource with given identifier found (-32000)  category="Response:bodySize:fetchBody" elapsed="0 ms" goroutine=315
WARN[0001] url:https://m.stripe.network/out-4.5.42.js method:GET err:fetching response body: No resource with given identifier found (-32000)  category="Response:bodySize:fetchBody" elapsed="0 ms" goroutine=315
WARN[0002] url:https://m.stripe.com/6 method:POST err:fetching response body: No resource with given identifier found (-32000)  category="Response:bodySize:fetchBody" elapsed="0 ms" goroutine=315
ERRO[0005] Failed to load resource: the server responded with a status of 429 ()  browser_source=network line_number=0 source=browser stacktrace="<nil>" url="https://o1012071.ingest.sentry.io/api/5977259/envelope/?sentry_key=e1363397e5574a048c87ce93858e83bf&sentry_version=7&sentry_client=sentry.javascript.nextjs%2F7.26.0"
WARN[0006] "/!\\ You are using legacy implementaion. Please update your code: use createWrapper() and wrapper.withRedux()."  source=browser-console-api
WARN[0006] "/!\\ You are using legacy implementaion. Please update your code: use createWrapper() and wrapper.withRedux()."  source=browser-console-api
WARN[0006] "/!\\ You are using legacy implementaion. Please update your code: use createWrapper() and wrapper.withRedux()."  source=browser-console-api
WARN[0006] "/!\\ You are using legacy implementaion. Please update your code: use createWrapper() and wrapper.withRedux()."  source=browser-console-api
WARN[0006] "/!\\ You are using legacy implementaion. Please update your code: use createWrapper() and wrapper.withRedux()."  source=browser-console-api
WARN[0006] "/!\\ You are using legacy implementaion. Please update your code: use createWrapper() and wrapper.withRedux()."  source=browser-console-api
WARN[0006] "/!\\ You are using legacy implementaion. Please update your code: use createWrapper() and wrapper.withRedux()."  source=browser-console-api
WARN[0006] "/!\\ You are using legacy implementaion. Please update your code: use createWrapper() and wrapper.withRedux()."  source=browser-console-api
panic: GoError: parsing remote object value: unexpected end of JSON input
running (00m06.1s), 1/1 VUs, 0 complete and 0 interrupted iterations
goroutine 101 [running]:-------------------------] 1 VUs  00m06.1s/10m0s  0/1 iters, 1 per VU
go.k6.io/k6/js/common.Throw(0x1407000?, {0x194cf40?, 0xc001f101a0?})
	go.k6.io/k6@v0.42.1-0.20230130080633-582ec4d3940c/js/common/util.go:20 +0x4d
github.com/grafana/xk6-browser/k6ext.Panic({0x195c988, 0xc00276f1d0}, {0x167e2a5, 0x1f}, {0xc00061f9d0?, 0x1, 0x1})
	github.com/grafana/xk6-browser@v0.0.0-00010101000000-000000000000/k6ext/panic.go:51 +0x2c6
github.com/grafana/xk6-browser/common.handleParseRemoteObjectErr({0x195c988, 0xc00276f1d0}, {0x194ce40?, 0xc0016a4468}, 0x0?)
	github.com/grafana/xk6-browser@v0.0.0-00010101000000-000000000000/common/remote_object.go:195 +0x125
github.com/grafana/xk6-browser/common.(*FrameSession).onConsoleAPICalled(0xc00132c0b0, 0xc00088e000)
	github.com/grafana/xk6-browser@v0.0.0-00010101000000-000000000000/common/frame_session.go:530 +0x1e5
github.com/grafana/xk6-browser/common.(*FrameSession).initEvents.func1()
	github.com/grafana/xk6-browser@v0.0.0-00010101000000-000000000000/common/frame_session.go:249 +0x565
created by github.com/grafana/xk6-browser/common.(*FrameSession).initEvents
	github.com/grafana/xk6-browser@v0.0.0-00010101000000-000000000000/common/frame_session.go:208 +0x1ab

See also the comparison between the console log messages in the k6 output vs the console.log message shown when navigating to the website through the browser:
Screenshot from 2023-02-24 09-21-27

Notice the null messages output in the browser console right at the moment that xk6-browser crashes.

Related: #777

@ArielKo1248
Copy link

ArielKo1248 commented Apr 20, 2023

Hi,

First of all, great working narrowing down the cause.

Second, I see there is an orphaned PR for this, any idea if this fix can make it into the next version as it is blocking our large scale performance testing.

Thanks so much!

@ankur22
Copy link
Collaborator

ankur22 commented Apr 20, 2023

@ArielKo1248,

We're going to add this to our current milestone.

@ankur22 ankur22 added the user request Requested by the community label Apr 20, 2023
@ankur22 ankur22 added this to the v0.10.0 milestone Apr 20, 2023
@ka3de ka3de self-assigned this Apr 21, 2023
@ka3de
Copy link
Collaborator Author

ka3de commented Apr 25, 2023

Hi @ArielKo1248 , the fix for this issue has just been merged into main, but won't be included in k6 until the next release. If you want you can use xk6 to build a custom version which includes k6 browser main version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working user request Requested by the community
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants