Skip to content

Comments

新增脚本支持顶级await#258

Merged
CodFrm merged 2 commits intoscriptscat:mainfrom
DreamNya:develop
Feb 1, 2024
Merged

新增脚本支持顶级await#258
CodFrm merged 2 commits intoscriptscat:mainfrom
DreamNya:develop

Conversation

@DreamNya
Copy link
Contributor

@DreamNya DreamNya commented Feb 1, 2024

简单测试了下没啥问题
不清楚是否会引起蝴蝶效应

@CodFrm
Copy link
Member

CodFrm commented Feb 1, 2024

调用的地方不多,应该没问题不大,先合了,近期有计划修下之前的bug发个fix版本

@CodFrm CodFrm merged commit 3a37af2 into scriptscat:main Feb 1, 2024
}
code = require + code;
return `with (context) return (()=>{\n${code}\n//# sourceURL=${chrome.runtime.getURL(
return `with (context) return (async ()=>{\n${code}\n//# sourceURL=${chrome.runtime.getURL(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我有个问题,这样相当于把脚本注入做成了异步,在比较严格要求document.start的脚本中会不会出现问题?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

脚本注入是在window上挂载一个闭包函数,然后执行。
这段代码外部还有一个闭包函数,这段代码只是在闭包中把同步改成异步,不影响闭包外代码。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我就是指的闭包内的这个代码,整个闭包相当于成为了异步,执行的优先级被拉低了,变成了微任务队列

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
我试了下没啥问题

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

确实没问题,感觉我得复习下Js基础了

@DreamNya DreamNya deleted the develop branch May 7, 2025 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants