catchpoint / WebPageTest.agent

Cross-platform WebPageTest agent
Other
213 stars 138 forks source link

Allow for running a script in an arbitrary frame context #584

Closed pmeenan closed 1 year ago

pmeenan commented 1 year ago

This enables cross-origin frame scripting for Chromium browsers (might work on iOS as well, haven't tested there yet).

It collects the available execution contexts from Chromium browsers and adds it to the page data json as execution_contexts:

"execution_contexts": [
    {
        "id": 2,
        "origin": "http:\/\/127.0.0.1:8888",
        "name": ""
    },
    {
        "id": 3,
        "origin": "https:\/\/codepen.io",
        "name": ""
    },
    {
        "id": 4,
        "origin": "https:\/\/cdpn.io",
        "name": ""
    }
],

It also adds a new script command, setExecutionContext that lets you match one of the available contexts by id, origin or name (though name is always blank as best as I can tell) and any future exec commands will target that context (and it can be reset to the main document by not passing a match).

navigate    https://codepen.io/juno_okyo/pen/yOjaEZ
setExecutionContext origin=https://cdpn.io
execAndWait document.getElementById('name-input').value = 'Bob'; fetch('https://cdpn.io/blank.html');
manpreet-compro commented 1 year ago

Hi @pmeenan Thanks for adding this option, highly useful. However I am not able to reset the execution context to main after performing some action inside iframe. Could you pls provide an example of that. Thanks!

pmeenan commented 1 year ago

@manpreet-compro As best as I can tell from the code, using setexecutioncontext with no parameters should result in the execution context being reset to the default.

manpreet-compro commented 1 year ago

@pmeenan Thanks for quick reply. I tried that already but that is not working as expected. Not sure what is the issue, will post details on a separate thread.

manpreet-compro commented 1 year ago

I have added details on https://github.com/WPO-Foundation/wptagent/issues/616. I am looking at the code in case I am able to locate the cause of this. If someone can help, that will be much appreciated