ozon 发表于 2022-12-26 16:11:06

【求助】利用navigator.clipboard.readText()在浏览器间传递文本

360极速浏览器X
想利用navigator.clipboard.readText()在浏览器间传递文本

脚本1如下 浏览器切到后台后,在其他地方复制文本,脚本读取剪贴板改变浏览器标题。任务栏上的窗口显示复制的文本。前台是正常的

问题 切到其他标签页 浏览器切到后台   标题就不变化了了,
脚本1

`// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @descriptiontry to take over the world!
// @author       You
// @include   http*
// @icon         https://www.google.com/s2/favicons?domain=bing.com
// @grant      none
// ==/UserScript==

(function() {
    'use strict';
    var i=0
    let timer= setInterval(() => {


      // document.title=i

      navigator.clipboard.readText().then((text)=>{

            console.log(text)
            console.log(i)
                  i+=1
            document.title=i+text
            //             if (GM_getValue('历史')!=text) {
            //               GM_setValue('历史',text)
            //             }
      })
    }, 500)
    // Your code here...
    })();`
   
脚本2,删掉 navigator.clipboard.readText()后,无论浏览器在前台还是后台,标题正常发生变化,是什么问题呢
`// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @descriptiontry to take over the world!
// @author       You
// @include   http*
// @icon         https://www.google.com/s2/favicons?domain=bing.com
// @grant      none
// ==/UserScript==

(function() {
    'use strict';
    var i=0
    let timer= setInterval(() => {

      i+=1
      document.title=i

    }, 500)
    // Your code here...
    })();`

李恒道 发表于 2022-12-26 17:39:47

navigator.clipboard.readText()这种极大取决于浏览器的
可能一旦切到后台这类函数就会休眠

ozon 发表于 2022-12-28 10:57:17

李恒道 发表于 2022-12-26 17:39
navigator.clipboard.readText()这种极大取决于浏览器的
可能一旦切到后台这类函数就会休眠
...

谢谢道哥   超纲了,我找到其它方法 把第二个浏览器装虚拟机里,虚拟机里浏览器能一直保持前台哈哈{:4_108:}
页: [1]
查看完整版本: 【求助】利用navigator.clipboard.readText()在浏览器间传递文本