Skip to content

Can't make Fetch API work #78

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

Open
php-coder opened this issue Sep 12, 2019 · 9 comments
Open

Can't make Fetch API work #78

php-coder opened this issue Sep 12, 2019 · 9 comments
Labels
workaround available There is a workaround available

Comments

@php-coder
Copy link
Contributor

php-coder commented Sep 12, 2019

As far as I understand, Fetch API is supported but I couldn't make it working.

On the code like fetch(request)... I got an error ReferenceError: "fetch" is not defined.
On the code like window.fetch(request) it fails with TypeError: Cannot find function fetch in object [object Window]

I use 2.36.0 version with htmlunit-driver and RobotFramework. The code for creating htmlunit driver is the following:

https://github.com/Hi-Fi/robotframework-seleniumlibrary-java/blob/fed6f0e95b5cf5a365f8357a9976ec9ed7ff7e1e/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/BrowserManagement.java#L782-L785

I expect that it will use default browser that is CHROME and it should have a support for Fetch API.

@rbri
Copy link
Member

rbri commented Sep 21, 2019

The fetch api is not supported so far - any help is welcome.

php-coder added a commit to php-coder/mystamps that referenced this issue Mar 7, 2020
@rbri rbri mentioned this issue Oct 14, 2020
@mvillafuertem
Copy link

mvillafuertem commented Jun 13, 2021

@rbi Any update? Any workaround? Thanks in advance

com.gargoylesoftware.htmlunit.ScriptException: ReferenceError: "fetch" is not defined. 
...
net.sourceforge.htmlunit.corejs.javascript.EcmaError: ReferenceError: "fetch" is not defined.

@rbi
Copy link
Contributor

rbi commented Jun 18, 2021

@mvillafuertem maybe you meant @rbri instead of @rbi ?

But as a coincidence I faced the same issue. I solved it by using a Polyfill that implements the fetch API based on XMLHttpRequest in the software under test.

@niloc132
Copy link

Perhaps a dumb question, but would it make sense to support JS polyfills directly in HtmlUnit to support features like fetch?

@rbri
Copy link
Member

rbri commented Feb 19, 2022

@niloc132 that sounds like a really good idea - i will experiment a bit with that.

@niloc132
Copy link

A patch showing how would make a great example for how to contribute other such features - I'm actually a bit surprised that other JS APIs havent been implemented with this before, leverage the rest of the engine working so well.

If you could also show very roughly how you would envision this working, I'd be happy to take a crack at this fix myself.

@rbri
Copy link
Member

rbri commented Feb 20, 2022

@niloc132 can you please open a separate issue for using a polyfill

@rbri
Copy link
Member

rbri commented Feb 20, 2022

@niloc132 - short progress update - i'm just made the first fetch request working based on your idea!!!!

@rbri
Copy link
Member

rbri commented Mar 11, 2022

since 2.59 there is finally a workaround based on the polyfill support - check out https://htmlunit.sourceforge.io/webclient.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
workaround available There is a workaround available
Projects
None yet
Development

No branches or pull requests

5 participants