X
Tippen Sie hierhin, um die Version dieser Website für Mobilgeräte aufzurufen.

Hilfeforum

clipboard.writeText failed only after call the crypto.subtle.digest api

Veröffentlicht

Test code:

   navigator.clipboard.writeText('test 1').then(function() {
       console.log('Copy to clipboard successed 1');
   }, function() {
       console.log('Copy to clipboard failed 1');
   });
   
   let test = await crypto.subtle.digest('SHA-256', dat);
   
   navigator.clipboard.writeText('test 2').then(function() {
       console.log('Copy to clipboard successed 2');
   }, function() {
       console.log('Copy to clipboard failed 2');
   });

Logs:

Copy to clipboard successed 1 Copy to clipboard failed 2

Test code: navigator.clipboard.writeText('test 1').then(function() { console.log('Copy to clipboard successed 1'); }, function() { console.log('Copy to clipboard failed 1'); }); let test = await crypto.subtle.digest('SHA-256', dat); navigator.clipboard.writeText('test 2').then(function() { console.log('Copy to clipboard successed 2'); }, function() { console.log('Copy to clipboard failed 2'); }); Logs: Copy to clipboard successed 1 Copy to clipboard failed 2
Zitieren

Mehr Details zum System

Anwendung

  • User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36

Weitere Informationen

jscher2000
  • Top 10 Contributor
8789 Lösungen 71880 Antworten
Veröffentlicht

See: https://developer.mozilla.org/docs/Web/API/Clipboard/writeText

I think the problem is that the second write is not directly linked to the user action that triggered the function.

See: https://developer.mozilla.org/docs/Web/API/Clipboard/writeText I think the problem is that the second write is not directly linked to the user action that triggered the function.
Hat Ihnen das weitergeholfen?
Zitieren
Veröffentlicht

Fragesteller

jscher2000 said

See: https://developer.mozilla.org/docs/Web/API/Clipboard/writeText I think the problem is that the second write is not directly linked to the user action that triggered the function.

The two test writes are in same function, only split by one line code of the "crypto.subtle.digest()".

I hope you can try my code, it's easy to reproduce the issue.

''jscher2000 [[#answer-1264544|said]]'' <blockquote> See: https://developer.mozilla.org/docs/Web/API/Clipboard/writeText I think the problem is that the second write is not directly linked to the user action that triggered the function. </blockquote> The two test writes are in same function, only split by one line code of the "crypto.subtle.digest()". I hope you can try my code, it's easy to reproduce the issue.
Hat Ihnen das weitergeholfen?
Zitieren
jscher2000
  • Top 10 Contributor
8789 Lösungen 71880 Antworten
Veröffentlicht

I think calling the asychronous function disconnects the second call from the original user-initiated event.

This old (open) bug may be relevant: https://bugzilla.mozilla.org/show_bug.cgi?id=1185052

I think calling the asychronous function disconnects the second call from the original user-initiated event. This old (open) bug may be relevant: https://bugzilla.mozilla.org/show_bug.cgi?id=1185052
Hat Ihnen das weitergeholfen?
Zitieren
Veröffentlicht

Fragesteller

Thank you for your reply, but I think they are different issues, I tried call some other async function instead, no problem at all.

Thank you for your reply, but I think they are different issues, I tried call some other async function instead, no problem at all.
Hat Ihnen das weitergeholfen?
Zitieren
cor-el
  • Top 10 Contributor
  • Moderator
17571 Lösungen 158915 Antworten
Veröffentlicht

Seems to be working for me.

Seems to be working for me.
Hat Ihnen das weitergeholfen?
Zitieren
Veröffentlicht

Fragesteller

cor-el said

Seems to be working for me.

Please try this one more time: https://jsfiddle.net/1jzdvy23/

Still not work for me, I tried:

Version 68.2.0 on Android Version 69.0.2 on Linux Version 70.0.1 on Linux

I also tried private window, not work.

duke-pc /home/duke # uname -a Linux duke-pc 5.0.9-gentoo #3 SMP Fri Apr 26 19:30:35 HKT 2019 x86_64 Intel(R) Core(TM) M-5Y71 CPU @ 1.20GHz GenuineIntel GNU/Linux

Last installed firefox from package: www-client/firefox-bin-70.0.1

''cor-el [[#answer-1264663|said]]'' <blockquote> Seems to be working for me. </blockquote> Please try this one more time: https://jsfiddle.net/1jzdvy23/ Still not work for me, I tried: Version 68.2.0 on Android Version 69.0.2 on Linux Version 70.0.1 on Linux I also tried private window, not work. duke-pc /home/duke # uname -a Linux duke-pc 5.0.9-gentoo #3 SMP Fri Apr 26 19:30:35 HKT 2019 x86_64 Intel(R) Core(TM) M-5Y71 CPU @ 1.20GHz GenuineIntel GNU/Linux Last installed firefox from package: www-client/firefox-bin-70.0.1
Hat Ihnen das weitergeholfen?
Zitieren
Stellen Sie eine Frage

Sie müssen sich mit Ihrem Benutzerkonto anmelden, um auf Beiträge zu antworten. Bitte stellen Sie eine neue Frage, wenn Sie noch kein Benutzerkonto haben.