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

disableJavaScriptFileLoading and script events #849

Closed
dteoh opened this issue Apr 11, 2023 · 4 comments · Fixed by #918
Closed

disableJavaScriptFileLoading and script events #849

dteoh opened this issue Apr 11, 2023 · 4 comments · Fixed by #918
Assignees
Labels
enhancement New feature or request

Comments

@dteoh
Copy link

dteoh commented Apr 11, 2023

Is your feature request related to a problem? Please describe.

Is it possible to get script.onload and script.onerror events to fire when disableJavaScriptFileLoading is used?

I have some code like:

return new Promise((resolve, reject) => {
  const script = document.createElement('script')
  script.src = 'https://something'
 
  script.onload = resolve
  script.onerror = reject

  document.head.appendChild(script)
})

When disableJavaScriptFileLoading is used, the promise won't resolve since the load event doesn't get fired.

Describe the solution you'd like

Could we extend the option to be: disableJavaScriptFileLoading: true | false | 'load' | 'error' | callback?

  • load: don't load the file, but fire the load event
  • error: don't load the file, but fire the error event
  • callback: give the script object as the first argument, the function returns one of true | false | 'load' | 'error' to customize the behaviour

WDYT?

@dteoh dteoh added the enhancement New feature or request label Apr 11, 2023
@capricorn86
Copy link
Owner

capricorn86 commented Apr 11, 2023

Hi @dteoh! 🙂

This is a tough one. I guess the most logical thing here would be to trigger an error event as the request technically failed. Would that solve your issue?

I'm not sure custom testing logic like this should be handled by Happy DOM, but I also understand that this is something that isn't very easy to implement a polyfill for as it would have to override internal logic.

@dteoh
Copy link
Author

dteoh commented Apr 13, 2023

Thank you for your feedback! Yes, I think firing an error event would be workable.

@capricorn86 capricorn86 self-assigned this May 12, 2023
capricorn86 added a commit that referenced this issue May 13, 2023
…g to fetch a CSS file or Javascript file when it has been disabled using "window.happyDOM.settings.*".
capricorn86 added a commit that referenced this issue May 13, 2023
…leloading-and-script-events

#849@minor: Adds support for triggering an error event when attemptin…
capricorn86 added a commit that referenced this issue May 13, 2023
…"|" as operators for finding attributes containing a word did not match when there was only one word.
@capricorn86
Copy link
Owner

@dteoh I have implemented a fix now that will trigger an error 🙂

You can read more about the release here:
https://github.com/capricorn86/happy-dom/releases/tag/v9.18.0

@dteoh
Copy link
Author

dteoh commented May 16, 2023

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants