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

frame() does not work properly when crossing domain #518

Open
yucongshub opened this issue Feb 1, 2024 · 0 comments
Open

frame() does not work properly when crossing domain #518

yucongshub opened this issue Feb 1, 2024 · 0 comments

Comments

@yucongshub
Copy link

yucongshub commented Feb 1, 2024

Hello, Before asking the question, I have seen similar questions, such as: #476 , but it does not have a good test and a result, so I want to reopen an issue to see if I can push the solution to the frame() problem.

When I used frame() to switch to iframe, it returned True, but I could not retrieve any elements in this iframe normally, such as using present() or read(), so I did some tests and got some maybe useful information

image
image
chrome engine error message:
[tagui] INPUT - [17] {"id":17,"method":"Runtime.evaluate","params":{"expression":"document.evaluate('//img',mainframe_context,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotLength"}} [tagui] OUTPUT - [17] {"id":17,"result":{"result":{"type":"object","subtype":"error","className":"TypeError","description":"TypeError: Failed to execute 'evaluate' on 'Document': parameter 2 is not of type 'Node'.\n at <anonymous>:1:10","objectId":"6975999204845677721.3.3"},"exceptionDetails":{"exceptionId":206,"text":"Uncaught","lineNumber":0,"columnNumber":9,"scriptId":"719","stackTrace":{"callFrames":[{"functionName":"","scriptId":"719","url":"","lineNumber":0,"columnNumber":9}]},"exception":{"type":"object","subtype":"error","className":"TypeError","description":"TypeError: Failed to execute 'evaluate' on 'Document': parameter 2 is not of type 'Node'.\n at <anonymous>:1:10","objectId":"6975999204845677721.3.4"}}}}

I switched frame() again so that I could get the switching process from the beginning, and then did some tests in the chrome console. The results are as follows:
[tagui] INPUT - [22] {"id":22,"method":"Runtime.evaluate","params":{"expression":"mainframe_context = document.evaluate('(//frame|//iframe)[@name=\"hahahaha\" or @id=\"hahahaha\"]',document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(0).contentDocument"}} [tagui] OUTPUT - [22] {"id":22,"result":{"result":{"type":"object","subtype":"null","value":null}}}

image
You can see that the content of the iframe cannot be obtained using contentDocument.

image
If you change it to contentWindow, it can be obtained, but if you use contentWindow.document, you will be prompted for cross-domain.

PS. When testing frame() in another non-cross-domain environment, it is normal to use contentDocument.
image


So other than using visual automation, can this problem be solved from the frame() side?

In addition, I also did some selenium tests, which can solve this problem through driver.switch_to.frame(), but my coding ability is limited and I cannot refer to selenium's methods to improve Tagui.

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

No branches or pull requests

1 participant