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

Not able to set the executionContext using Id of iframe #623

Open
yugal-compro opened this issue Jun 14, 2023 · 8 comments · Fixed by #629
Open

Not able to set the executionContext using Id of iframe #623

yugal-compro opened this issue Jun 14, 2023 · 8 comments · Fixed by #629

Comments

@yugal-compro
Copy link

Use Case:

I would like to change the execution context using Id of the iframe

I referred to the documentation https://docs.webpagetest.org/scripting/#setexecutioncontext for switching the execution context and was able to switch it using origin but was unable to switch the execution context using the ID of the cross-origin iframe.

Script:

navigate https://codepen.io/juno_okyo/pen/yOjaEZ
setExecutionContext ID=result
execAndWait document.getElementById('name-input').value = 'Yugal Vashishth'
execAndWait document.querySelector('#form > button').click()

Expected Action:

  1. Change the execution context using Id of the iframe
  2. Type 'Yugal Vashishth' inside input
  3. Click 'OK' button

Issue Faced:
The input value is not updating to 'Yugal Vashishth'
This script works fine when I change the execution context using the 'origin' of the iframe but It doesn't work when I use the 'ID' of the iframe.

Note:
I am using ID instead of origin because I have to access two iframes having the same origin, so when I set the execution context using 'origin' it always returns the execution context of the first iframe but I would also like to access the second iframe.

@pmeenan
Copy link
Contributor

pmeenan commented Jun 21, 2023

Sorry for the confusion in the docs, the "ID" referred isn't the frame ID in the DOM, it's the dev tools ID for the execution context. If you look at the JSON result of a test it will have the list of all of the execution contexts with the ID's and origins.

I'm pretty sure the execution context's are just sequentially numbered but you'll want to verify the ID in the JSON

@pmeenan
Copy link
Contributor

pmeenan commented Jun 21, 2023

FWIW, for that pen, these are the execution context ID's and origins (at least when tested with desktop):

"execution_contexts": [
    {
        "id": 2,
        "origin": "https:\/\/cdpn.io",
        "name": ""
    },
    {
        "id": 1,
        "origin": "https:\/\/codepen.io",
        "name": ""
    },
    {
        "id": 3,
        "origin": "https:\/\/codepen.io",
        "name": ""
    },
    {
        "id": 5,
        "origin": "https:\/\/js.stripe.com",
        "name": ""
    },
    {
        "id": 6,
        "origin": "https:\/\/m.stripe.network",
        "name": ""
    }
],

@pmeenan
Copy link
Contributor

pmeenan commented Jun 21, 2023

It looks like the 2 stripe origins are actually different so you could probably use the named origin as well.

@yugal-compro
Copy link
Author

Thanks for your response, I tried setting the execution context using the ID given in the JSON result still, this is not changing the execution context

@aartajew
Copy link

aartajew commented Jun 29, 2023

There is a type mismatch when setting context by id key.

You are comparing string with integer which results in false here:
https://github.com/WPO-Foundation/wptagent/blob/eb86253f0e27463a9ccf2268d41f13e370f7a1bc/internal/devtools.py#L1250

Setting by origin works ok, see here: https://www.webpagetest.org/result/230629_AiDcS7_6GB/
Setting by id fails, see here: https://www.webpagetest.org/result/230629_AiDc1W_6GC/

Here are the contexts from JSON:

"execution_contexts":
[
    {
        "id": 2,
        "origin": "https://cdpn.io",
        "name": ""
    },
    {
        "id": 1,
        "origin": "https://codepen.io",
        "name": ""
    },
    {
        "id": 3,
        "origin": "https://codepen.io",
        "name": ""
    },
    {
        "id": 5,
        "origin": "https://js.stripe.com",
        "name": ""
    },
    {
        "id": 6,
        "origin": "https://m.stripe.network",
        "name": ""
    }
]

So for now setting context by id is impossible.
Could you fix this please? Thx in advance 😄

@aartajew
Copy link

For a temporary workaround you can use jQuery for switching to another frame (same origin only):

execAndWait $("#content-iframe").contents().find("#Assessments_Navigation_Bar1 .section_0 .button")[0].click()

@aartajew
Copy link

@pmeenan
Copy link
Contributor

pmeenan commented Jul 25, 2023

Doesn't look like it. The prod branch hasn't been updated since the fix landed.

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

Successfully merging a pull request may close this issue.

3 participants