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: The string to be encoded contains characters outside of the Latin1 range #3019

Closed
christian-bromann opened this issue Jan 23, 2025 · 2 comments · Fixed by #3031 · May be fixed by #3018
Closed

error: The string to be encoded contains characters outside of the Latin1 range #3019

christian-bromann opened this issue Jan 23, 2025 · 2 comments · Fixed by #3031 · May be fixed by #3018
Assignees

Comments

@christian-bromann
Copy link
Contributor

See original issue: webdriverio/webdriverio#14089

What happened?

When I use utf8 chars in e.g. mock.respond("Hello 🌍!"); I get an error

{
error: "unknown error",
id: 13,
message: "Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.",
stacktrace: "InvalidCharacterError: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.
    at getCdpBodyFromBiDiBytesValue (<anonymous>:630:15682)
    at NetworkRequest.provideResponse (<anonymous>:630:11422)
    at NetworkProcessor.provideResponse (<anonymous>:306:2340)
    at #processCommand (<anonymous>:469:5683)
    at CommandProcessor.processCommand (<anonymous>:469:8152)
    at #handleIncomingMessage (<anonymous>:758:321)
    at WindowBidiTransport.window.onBidiMessage (<anonymous>:868:2182)
    at <anonymous>:1:1",
type: "error"
}

There is a related bug that that touches the same subject webdriverio/webdriverio#7710 that had this webdriverio/webdriverio#7711 pull request

What is your expected behavior?

get the response Hello 🌍!

How to reproduce the bug.

import { describe, it } from "mocha";
import { browser } from "@wdio/globals";

describe("Test", () => {
  it("should mock hello world", async () => {
    const playground_mock = await browser.mock("https://example.org");

    playground_mock.respond(
      "Hello 🌍!"
      // {
      //   value: "Hello 🌍!",
      // }
    );
    await browser.url("https://example.org/");
  });
});

Relevant log output

from my terminal (info log level)

[0-0] 2025-01-20T10:24:08.126Z INFO webdriver: BIDI COMMAND network.provideResponse {"request":"1EE5DB020A0BEF95CB1CD099A4AE0A05","body":{"type":"string","value":"Hello 🌍!"}}
[0-0] 2025-01-20T10:24:08.131Z INFO webdriver: BIDI RESULT {"error":"unknown error","id":13,"message":"Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.","stacktrace":"InvalidCharacterError: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.\n    at getCdpBodyFromBiDiBytesValue (\u003Canonymous>:630:15682)\n    at NetworkRequest.provideResponse (\u003Canonymous>:630:11422)\n    at NetworkProcessor.provideResponse (\u003Canonymous>:306:2340)\n    at #processCommand (\u003Canonymous>:469:5683)\n    at CommandProcessor.processCommand (\u003Canonymous>:469:8152)\n    at #handleIncomingMessage (\u003Canonymous>:758:321)\n    at WindowBidiTransport.window.onBidiMessage (\u003Canonymous>:868:2182)\n    at \u003Canonymous>:1:1","type":"error"}
[0-0] Error in "Test.should mock hello world"
Error: Timeout of 60000ms exceeded. The execution in the test "Test should mock hello world" took too long. Try to reduce the run time or increase your timeout for test specs (https://webdriver.io/docs/timeouts). (/home/user/workspace/tests/src/bug.test.ts)
    at createTimeoutError (/home/user/workspace/tests/node_modules/mocha/lib/errors.js:498:15)
    at Runnable._timeoutError (/home/user/workspace/tests/node_modules/mocha/lib/runnable.js:429:10)
    at Timeout.<anonymous> (/home/user/workspace/tests/node_modules/mocha/lib/runnable.js:244:24)
    at listOnTimeout (node:internal/timers:569:17)
    at process.processTimers (node:internal/timers:512:7)


from the BiDi-CDP Mapper tab:

bidi:RECV  {"channel":"/3/nochan/bidi","id":13,"method":"network.provideResponse","params":{"body":{"type":"string","value":"Hello 🌍!"},"request":"1EE5DB020A0BEF95CB1CD099A4AE0A05"}}
bidi {}
debug:queue Processing event: network.provideResponse
bidi:SEND  { "type": "error", "id": 13, "error": "unknown error", "message": "Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.", "stacktrace": "InvalidCharacterError: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.\n at getCdpBodyFromBiDiBytesValue (<anonymous>:630:15682)\n at NetworkRequest.provideResponse (<anonymous>:630:11422)\n at NetworkProcessor.provideResponse (<anonymous>:306:2340)\n at #processCommand (<anonymous>:469:5683)\n at CommandProcessor.processCommand (<anonymous>:469:8152)\n at #handleIncomingMessage (<anonymous>:758:321)\n at WindowBidiTransport.window.onBidiMessage (<anonymous>:868:2182)\n at <anonymous>:1:1", "channel": "/3/nochan/bidi" }

One way to fix this is to use the TextEncoder to parse it into base64 and back. However this seems a bit redundant, is this something that the browser could better handle?

@OrKoN
Copy link
Collaborator

OrKoN commented Jan 23, 2025

@Lightning00Blade could you please take a look and add corresponding tests?

@christian-bromann
Copy link
Contributor Author

Thanks you all 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants