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

Dynamically-created iframe with the file: protocol is not loading properly #7983

Open
drrnkin opened this issue Aug 29, 2023 · 14 comments
Open

Comments

@drrnkin
Copy link

drrnkin commented Aug 29, 2023

What is your Scenario?

A test loads a page that dynamically inserts an iframe. element and loads that content. The iframe fails to be recognized.

What is the Current behavior?

In Chrome, the iframe can be seen to load correctly (if you watch), but TestCafe can't detect this and issues the message "Content of the iframe in which the test is currently operating did not load.". Note that in versions 1.x and 2.x Chrome worked correctly, but it's changed in 3.x.

What is the Expected behavior?

Simple test at https://github.com/drrnkin/testcafe-iframe should pass. The test should detect the content in the iframe that is dynamically created by a script in the iframe. Note that the test passes in Chrome in TestCafe 1.x or 2.x, but not 3.x.

Expected: test should pass in both Chrome and Firefox. Note that there's a related bug for Firefox #7991

What is your public website URL? (or attach your complete example)

https://github.com/drrnkin/testcafe-iframe

What is your TestCafe test code?

See provided repo

Your complete configuration file

See provided repo

Your complete test report

No response

Screenshots

No response

Steps to Reproduce

  1. Clone the repo https://github.com/drrnkin/testcafe-iframe
  2. yarn
  3. yarn build
  4. yarn test-chrome

TestCafe version

3.3.0

Node.js version

v16.20.2

Command-line arguments

See Steps to Reproduce

Browser name(s) and version(s)

Chrome 116.0.5845.111 (currently latest)

Platform(s) and version(s)

Windows 10

Other

No response

@drrnkin drrnkin added the TYPE: bug The described behavior is considered as wrong (bug). label Aug 29, 2023
@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Aug 29, 2023
@ridginald
Copy link

+1 on this - macOs experiences the same issue, and prevents us from having all our jobs running on the testcafe same version

@AlexKamaev
Copy link
Contributor

Please modify your example a little. Try to remove file system paths from the page property in the test and from the iframe src attribute as follows:

.page("http://localhost:8080/hostApp.html")
createIframe(document.body, "http://localhost:8080/iframe.html")

Then, please launch the http-server module from your project directory.

npx http-server

It is working on my side.
As for the FF error, I've reproduced it as well. However, I cannot give any estimates on when the issue with FF will be resolved.
We can research the FF issue. However, we need to have a simpler testcafe-iframe-bundle.js file to debug it efficiently.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Aug 30, 2023
@AlexKamaev AlexKamaev added STATE: Need clarification An issue lacks information for further research. and removed TYPE: bug The described behavior is considered as wrong (bug). labels Aug 30, 2023
@drrnkin drrnkin changed the title Dynamically-created iframe not loading propertly Dynamically-created iframe not loading properly Aug 30, 2023
@drrnkin
Copy link
Author

drrnkin commented Aug 30, 2023

There are no file system paths per se since all paths are relative (but you're right that the original ends up being a local file URL). Starting the server and changing the path to .page("http://localhost:8080/hostApp.html") indeed does not suffer the problem in Chrome.. However, simply describing something else that doesn't suffer from the bug doesn't negate the fact that there's a bug as originally described 😃

The provided test case worked fine in Chrome in 1.x and 2.x so this is a regression. You can see this by running yarn add testcafe@2 and then yarn test-chrome again, which passes in 1.x or 2.x. If you are saying that local URLs are not supported by TestCafe 3.x, please point me to the docs that describe this breaking change. Otherwise, the Chrome bug as described still stands.

As for the Firefox issue being difficult to deal with, the main.ts file simply imports Highcharts (a popular charting library: https://www.highcharts.com/) and that's enough to cause the issue. I don't have the source so I can't whittle it down further. All I can say is it has something to do with querySelectorAll as per the console error.

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Aug 30, 2023
@github-actions github-actions bot removed the STATE: Need clarification An issue lacks information for further research. label Aug 30, 2023
@AlexKamaev
Copy link
Contributor

I agree that the described behavior is not expected, so we can consider it as a bug. I recommend that you use the described workaround until the issue is fixed.

As for the FF issue, please create a separate ticket using the following link: https://github.com/DevExpress/testcafe/issues/new?assignees=&labels=TYPE%3A+bug&projects=&template=bug_report.yaml.

@drrnkin
Copy link
Author

drrnkin commented Aug 31, 2023

OK thanks, I trimmed this one to not mention Firefox, and created a Firefox-specific bug at #7991.

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Aug 31, 2023
@AlexKamaev AlexKamaev added HAS WORKAROUND and removed STATE: Need response An issue that requires a response or attention from the team. labels Sep 1, 2023
@drrnkin
Copy link
Author

drrnkin commented Sep 1, 2023

FYI I noticed you added the "HAS_WORKROUND" flag. The workaround does indeed work around the issue, but we wouldn't be able to use it in our context, so this bug prevents us from upgrading to 3.x.

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Sep 1, 2023
@AlexKamaev
Copy link
Contributor

@drrnkin We understand your point, so that's why we consider this issue a bug. Even though we use this label to plan our workload, the HAS_WORKAROUND flag does not mean that we ignore the issue.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Sep 4, 2023
@AlexKamaev AlexKamaev self-assigned this Sep 7, 2023
@AlexKamaev AlexKamaev changed the title Dynamically-created iframe not loading properly Dynamically-created iframe with file: protocol is not loading properly Sep 12, 2023
@AlexKamaev AlexKamaev changed the title Dynamically-created iframe with file: protocol is not loading properly Dynamically-created iframe with the file: protocol is not loading properly Sep 12, 2023
@AlexKamaev
Copy link
Contributor

I researched the issue and found that it can be resolved by adding the --allow-file-access-from-files flag to your Chrome browser as follows:

testcafe "chrome --allow-file-access-from-files" test.js

I checked your usage scenario, and it works as expected. Please try to use this approach and share your results with us.

@AlexKamaev AlexKamaev added the STATE: Need clarification An issue lacks information for further research. label Sep 13, 2023
@drrnkin
Copy link
Author

drrnkin commented Sep 14, 2023

Yes, that workaround did pass for me. To be clear I locally modified the provided sample as follows (escaped quotes are important).

	"test-chrome": "testcafe \"chrome --allow-file-access-from-files\" tests",

and then ran "yarn test-chrome".

Some points to consider:

  1. The iframe works without that flag when loaded manually in a browser, but not in TestCafe 3.x
  2. It worked in TestCafe 2.x without that flag.
  3. It would be difficult for us to apply the workaround across many small repos, not to mention other browser types would probably need similar workarounds.

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Sep 14, 2023
@github-actions github-actions bot removed the STATE: Need clarification An issue lacks information for further research. label Sep 14, 2023
@AlexKamaev
Copy link
Contributor

AlexKamaev commented Sep 14, 2023

  1. Yes. TestCafe injects a lot of client script code to the page to communicate between the browser and the TestCafe server. Browser does not allow this code to work correctly when you use iframes with the file: protocol.

  2. In version 3.0 and newer, TestCafe runs tests with the Native Automation option enabled by default. In Native Automation mode, TestCafe does not use the URL rewriting mechanism as in the previous version. Previously, TestCafe rewrote URL, so even files were opened under http protocol. If you want, you can use the --disable-native-automation flag or the corresponding property in config file to disable Native Automation.

  3. We'll discuss the issue with the team. However, we cannot recommend any other solution at this time.

other browser types would probably need similar workarounds

Please note that Native Automation mode is enabled only in Chromium-based browsers (Chrome, Edge, etc.). You don't need to add this option to other browsers.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Sep 14, 2023
AlexKamaev added a commit that referenced this issue Sep 14, 2023
@drrnkin
Copy link
Author

drrnkin commented Sep 14, 2023

Thanks, I confirmed that creating a .testcaferc.json file with the content you referenced is another workaround.

{
	"disableNativeAutomation": true
}

Just a suggestion -- I wonder if TestCafe could automatically disable that feature by itself when it encounters a file:// url?

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Sep 14, 2023
@AlexKamaev
Copy link
Contributor

I'm happy to hear that the workaround resolved the issue for now.

I wonder if TestCafe could automatically disable that feature by itself when it encounters a file:// url

TestCafe cannot disable that feature automatically. However, we will discuss how to improve user experience with the Native Automation mode.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Sep 15, 2023
Copy link

This issue has been automatically marked as stale because it has not had any activity for a long period. It will be closed and archived if no further activity occurs. However, we may return to this issue in the future. If it still affects you or you have any additional information regarding it, please leave a comment and we will keep it open.

@github-actions github-actions bot added the STATE: Stale An outdated issue that will be automatically closed by the Stale bot. label Mar 16, 2024
@drrnkin
Copy link
Author

drrnkin commented Mar 16, 2024

Commenting to remove stale state

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Mar 16, 2024
@github-actions github-actions bot removed the STATE: Stale An outdated issue that will be automatically closed by the Stale bot. label Mar 17, 2024
@PavelMor25 PavelMor25 removed the STATE: Need response An issue that requires a response or attention from the team. label Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants