Bug 224422 - REGRESSION(r275262) [WebDriver] Make automation JS code aware of injected script headers
Summary: REGRESSION(r275262) [WebDriver] Make automation JS code aware of injected scr...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebDriver (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Lauro Moura
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-04-11 21:08 PDT by Lauro Moura
Modified: 2021-04-13 15:43 PDT (History)
4 users (show)

See Also:


Attachments
Patch (2.20 KB, patch)
2021-04-11 21:16 PDT, Lauro Moura
no flags Details | Formatted Diff | Diff
Patch (2.56 KB, patch)
2021-04-12 14:13 PDT, Lauro Moura
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Lauro Moura 2021-04-11 21:08:15 PDT
https://trac.webkit.org/changeset/275262/webkit changed the injected scripts to have the "//# sourceURL=__InjectedScript_*.js" header.

This led to about 1.5k WebDriver tests to fail. Most (all?) of them with the following error:

E           JavascriptErrorException: javascript error (500): Unexpected keyword 'function'. Expected ')' to end a compound expression.                                                                    
                                                                                                                                                   
body       = {'using': 'css selector', 'value': 'input'}
err        = <JavascriptErrorException http_status=500>
method     = 'POST'
response   = <Response status=500 error=<JavascriptErrorException http_status=500>>
self       = <Session bb6344e1-8a15-487d-b05c-0cdc06fc85ce>
timeout    = None
url        = 'session/bb6344e1-8a15-487d-b05c-0cdc06fc85ce/element'

When evaluating the following expression in the test:

element = session.find.css("input", all=False)

The issue happens due to WebAutomationSessionProxy.js wrapping the executing code in "(async <CODE>)". With the header, this resulted in the following code:

```
(async //# __injectedScript...
 function (...) {...})
```

And the "Unexpected keyword" error appeared.

A candidate fix is to skip the header lines from the function code before wrapping it in async. Patch in the next comment.
Comment 1 Lauro Moura 2021-04-11 21:16:15 PDT
Created attachment 425718 [details]
Patch
Comment 2 Carlos Garcia Campos 2021-04-12 01:15:09 PDT
Comment on attachment 425718 [details]
Patch

Is that comment useful tor WebDriver scripts? Maybe we could add an option to make-js-file-arrays.py  not to include the directive and use that for WebDriver scripts?
Comment 3 Lauro Moura 2021-04-12 10:29:55 PDT
(In reply to Carlos Garcia Campos from comment #2)
> Comment on attachment 425718 [details]
> Patch
> 
> Is that comment useful tor WebDriver scripts? Maybe we could add an option
> to make-js-file-arrays.py  not to include the directive and use that for
> WebDriver scripts?

I think it's not directly used by the WebDriver code, but intended for the inspector UI, so there is the scenario of pausing a webdriver session to inspect the code in the browser. In this case, IIUC, the directive should be present in the source.
Comment 4 BJ Burg 2021-04-12 13:50:00 PDT
Comment on attachment 425718 [details]
Patch

the //# directive is a source map directive. It labels these evaluations, which is essential when debugging WebAutomationSessionProxy code via Web Inspector.

Perhaps you could search for the first non-comment line and wrap the remainder of the evaluation there, lifting any initial comments outside the async statement.
Comment 5 Lauro Moura 2021-04-12 14:13:27 PDT
Created attachment 425789 [details]
Patch
Comment 6 BJ Burg 2021-04-13 09:02:30 PDT
Comment on attachment 425789 [details]
Patch

r=me
Comment 7 EWS 2021-04-13 15:42:43 PDT
Committed r275915 (236479@main): <https://commits.webkit.org/236479@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 425789 [details].
Comment 8 Radar WebKit Bug Importer 2021-04-13 15:43:15 PDT
<rdar://problem/76614329>