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

Seeing %MatchError{term: {:error, :obscured}} when calling execute_script with certain kinds of JavaScript #383

Closed
mhanberg opened this issue Jul 30, 2018 · 9 comments

Comments

@mhanberg
Copy link
Member

Issue

Elixir: 1.6.4
Erlang: 20.2.2
Google Chrome: Version 67.0.3396.99 (Official Build) (64-bit)
ChromeDriver: 2.36.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)

When attempting to use await with the execute_script function, I have experienced a %MatchError{term: {:error, :obscured}}.

session
|> visit(url)
|> execute_script("""
const resp = await fetch("#{url}").then(r => r.text());
return resp;
""")
|> page_source

This line of code works in the dev console on Chrome.

I have been told that %MatchError but might the incorrect error for this case.


I was able to work my way around this without needing to use await.

@keathley
Copy link
Member

I think the issue is here: https://github.com/keathley/wallaby/blob/master/lib/wallaby/httpclient.ex#L70.

This was called out in an earlier issue but now I'm not sure what that issue was or why this wasn't fixed before. We should remove that status check and find a better way to surface errors. Returning the actual error text from the http response would be a good start and help illuminate whats really going on.

@keathley
Copy link
Member

@mhanberg Do you have a minimal test case we can use to re-produce this locally?

@mhanberg
Copy link
Member Author

@keathley The test case can be found here: https://github.com/mhanberg/wallaby_bug_demo.

@keathley
Copy link
Member

keathley commented Aug 6, 2018

@mhanberg Does this fail pretty reliably for you? I'm not seeing any errors. I just checked and it seems I'm running chromedriver 2.4 (same chrome version as you). Can you confirm that this error is present after updating to the latest chromedriver?

@mhanberg
Copy link
Member Author

mhanberg commented Aug 6, 2018

@keathley I upgraded to chromedriver 2.41 and the error persists.

Also, to clarify, the test case I provided may have been misleading, as it asserted that the MatchError would be raised, so a passing test indicates the problem is there. Sorry about that.

I have updated the test to fail when a MatchError is thrown.

@keathley
Copy link
Member

keathley commented Aug 7, 2018

Oh! Thats my fault. Should have looked closer at the test itself. Thats what I get for trying to rush around. Thanks for the clarity 👍.

mhanberg added a commit to mhanberg/wallaby that referenced this issue Oct 20, 2018
This will still throw, but will present the actual error message related
to the exception.
@mhanberg
Copy link
Member Author

It looks like the message that comes with this error is

Interactive Elixir (1.6.4) - press Ctrl+C to exit (type h() ENTER for help)
pry(1)> response
%{
  "sessionId" => "d701c566b82095684715f9eddc8adcbb",
  "status" => 13,
  "value" => %{
    "message" => "unknown error: Runtime.evaluate threw exception: SyntaxError: await is only valid in async function\n  (Session info: headless chrome=69.0.3497.100)\n  (Driver info: chromedriver=2.41.578706 (5f725d1b4f0a4acbf5259df887244095596231db),platform=Mac OS X 10.14.0 x86_64)"
  }
}

Which makes sense to me after reading PR #374

@keathley I have gone ahead and made a PR #389 to keep the error message instead of :obscure. Let me know what you think.

@keathley
Copy link
Member

Thanks @mhanberg I'll take a look 👍

keathley pushed a commit that referenced this issue Oct 29, 2018
…389)

* #383 Return error message for obscure responses

This will still throw, but will present the actual error message related
to the exception.

* Remove trailing comma that was causing a compilation warning
@mhanberg
Copy link
Member Author

Fixed in #389

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

No branches or pull requests

2 participants