JingMatrix / ChromeXt

UserScript and DevTools supports for Chromium based and WebView based browsers
https://jingmatrix.github.io/ChromeXt/
GNU General Public License v3.0
700 stars 39 forks source link

Different `window` objects for the contexts of @require and the UserScript #106

Closed WhiteSevs closed 1 year ago

WhiteSevs commented 1 year ago

脚本👉https://greasyfork.org/zh-CN/scripts/445489-%E7%BD%91%E7%9B%98%E9%93%BE%E6%8E%A5%E8%AF%86%E5%88%AB

@require的库内进行window判断时,通过传递参数的window为被Proxy的window,而@require库内的window却是unsafeWindow

{C0B6964F-5A61-4366-AB3E-55F38773560C} {E554E932-39B7-43fe-A00B-72178DA485EF}

JingMatrix commented 1 year ago

Since you call the function DOMUtils.width from your own UserScript, where unsafeWindow is not granted, the window object is surely a proxied one.

For the context of @require, the window object is always the global one so that global definition could work. By contrast, the globalThis object is proxied.

To solve the issue for your script, either you ask to grant unsafeWindow, or in the library DOMUtils, set your window object to be globalThis.

WhiteSevs commented 1 year ago

感谢,我使用globalThis代替了window,脚本可以正常工作了