I still can't get GM api from unsafeWindow when i open the mountGmApi. after debug i found the monkeyWindow is proxy and can not map GM key from proxy, code here
export const mountGmApiFn = (meta: ImportMeta) => {
const key = `__monkeyWindow-` + new URL(meta.url).origin;
// @ts-ignore
const monkeyWindow: Window = document[key];
if (!monkeyWindow) {
console.log(`[vite-plugin-monkey] not found monkeyWindow`);
return;
}
// @ts-ignore
window.unsafeWindow = window;
console.log(`[vite-plugin-monkey] mount unsafeWindow to unsafeWindow`);
const mountedApiList: string[] = [];
Object.entries(monkeyWindow)
.filter(([k]) => k.startsWith('GM'))
.forEach(([k, fn]) => {
// @ts-ignore
window[k] = fn;
mountedApiList.push(k);
});
console.log(
`[vite-plugin-monkey] mount ${mountedApiList.length} GM_api to unsafeWindow`,
);
};
I still can't get GM api from unsafeWindow when i open the mountGmApi. after debug i found the monkeyWindow is proxy and can not map
GM
key from proxy, code hereI think the code should be: