lisonge / vite-plugin-monkey

A vite plugin server and build your.user.js for userscript engine like Tampermonkey, Violentmonkey, Greasemonkey, ScriptCat
MIT License
1.35k stars 71 forks source link

dev模式下“run-at”设置为“document-start”仍不能保证在一开始执行 #145

Closed Lu-Jiejie closed 6 months ago

Lu-Jiejie commented 6 months ago

在某个网站,我在设置 @run-atdocument-start 后,在dev模式下执行如下脚本,输出的结果会比build模式少很多

function Observer() {
  const observer = new MutationObserver((mutationList) => {
    mutationList.forEach((mutation) => {
      mutation.addedNodes.forEach((ele) => {
        if (ele.nodeName === 'IMG')
          console.log(ele)
      })
    })
  })
  observer.observe(document.documentElement, {
    childList: true,
    subtree: true,
    attributes: true
  })
}
Observer()

有啥办法能让dev模式下脚本加载时机与build相同吗

lisonge commented 6 months ago

不借助外部工具貌似是不可行的

你可以参考 https://github.com/lisonge/vite-plugin-monkey/discussions/60#discussioncomment-5328945

Lu-Jiejie commented 6 months ago

感谢解答