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

Playing audio will stop loading page and JS execution #1379

Closed
fifv opened this issue Jan 24, 2024 · 7 comments · Fixed by #1857
Closed

Playing audio will stop loading page and JS execution #1379

fifv opened this issue Jan 24, 2024 · 7 comments · Fixed by #1857
Labels
web/javascript JS or web related

Comments

@fifv
Copy link

fifv commented Jan 24, 2024

Describe the bug

My dict (see below) uses javascript to .click() to play audio, but it will stop loading all following pages/dicts. (seems unrelated to click itself, as clicking on a random element is ok, only playing audio has the problem.)

A workaround to this is to listen on DOMContentLoaded event to wait page loading finished, but that takes too long to wait long webpages like wikipedia/wiktionary (almost 5 seconds). (this seems to be the built-in audio playing logic, which plays audio after everything has loaded).

To Reproduce
Steps to reproduce the behavior:

  1. In any dict, use javascript to trigger sound playing like: document.querySelector(".pf a.visible")?.click()
  2. Unloaded dict won't show

Affected Dictionaries

The Little Dict (downloaded from here), then modified the fy.js that only containes:
document.querySelector(".pf a")?.click()

Expected behavior
The audio played and page continues loading.

Screenshots
Enable js audio play:
image

Disable js audio play:
image

OS and software versions

Goldendict-ng 24.01.22-LoongYear.20240122.3dddb3be
Qt 6.6.1 Visual C++ Compiler 192930153 windows winnt 10.0.22631 x86_64-little_endian-llp64
Flags:USE_XAPIAN MAKE_ZIM_SUPPORT USE_ICONV MAKE_CHINESE_CONVERSION_SUPPORT no_ffmpeg_player

@LakeishaKowalczyk
Copy link

Manual clicks have the same effect

@xiaoyifang
Copy link
Owner

I have not found the dictionary with the link provided above

@LakeishaKowalczyk
Copy link

try this
https://downloads.freemdict.com/尚未整理/共享2020.5.11/content/0_audio/The little dict/
https://forum.freemdict.com/t/topic/22813
https://forum.freemdict.com/t/topic/9947

Load more dictionaries (dozens) and it's easier to click on
In fact all dictionaries are the same, as long as you click on the pronunciation of any dictionary, the subsequent content of all dictionaries will not be loaded, and JSs will stop running.

@shenlebantongying shenlebantongying changed the title Playing audio will stop loading page Playing audio will stop loading page and JS execution Oct 21, 2024
@xiaoyifang
Copy link
Owner

xiaoyifang commented Oct 21, 2024

QWebEngineView does not has the urlClick signal . The gd-ng has used the following trick to simulate a url click event.

  1. User click <a> in the page ,
  2. gd-custom.js will catch the event(the gd-custom.js is created to handle invalid url) and throw an event emitClickedEvent .
  3. there is an url click event articleview.linkClickedInHtml been fired in the QWebEngineView , then an actual event linkClicked has been fired.
  4. linkClicked signal connected with openLink which handled the audio download(temporarily) and play.

The possible issue here is that ,

  1. gd-custom.js has done the job pooly.

add the following line to gd-custom.js?

event.preventDefault();

@xiaoyifang
Copy link
Owner

add the following line to gd-custom.js?

event.preventDefault();

checked. Not this reason.

@xiaoyifang

This comment was marked as off-topic.

@xiaoyifang
Copy link
Owner

xiaoyifang commented Oct 23, 2024

Guess:

for a normal webview like chrome. when click the anchor link in the page ,the page will try to load the anchor url in this webview which also stop the previous normal loading.
I guess the behavior here is the default action of webengine view.

Need find a solution to prevent this default action.

I tested the QWebEngineUrlRequestInterceptor and acceptNavigationRequest , the anchor's url has already been catched ,and blocked too.
But the webview's loadFinish signal is still emited with the result=false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
web/javascript JS or web related
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants