Skip to content

[BUG] 调用 GM_addStyle 产生错误:Cannot read properties of undefined (reading 'code') #676

Closed

Description

@QiWei

问题描述

脚本是 东方永页机 1.9.37.123

f6810778-3bac-4351-b35f-b7b5d38985f2:2 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'code')
    at C.GM_addStyle (f6810778-3bac-4351-b…7b5d38985f2:2:16393)
    at SideController.addToStage (Pagetual.user.js:5077:33)
    at SideController.setup (Pagetual.user.js:4670:18)
    at Pagetual.user.js:4373:36
GM_addStyle	@	f6810778-3bac-4351-b35f-b7b5d38985f2:2
addToStage	@	Pagetual.user.js:5077
setup	@	Pagetual.user.js:4670
(anonymous)	@	Pagetual.user.js:4373
await in (anonymous)		
setRule	@	Pagetual.user.js:2076
getRule	@	Pagetual.user.js:2176
await in getRule		
initPage	@	Pagetual.user.js:4252
initPage	@	Pagetual.user.js:7872
(anonymous)	@	Pagetual.user.js:10304
(anonymous)	@	Pagetual.user.js:7722
await in (anonymous)		
initSavedRules	@	Pagetual.user.js:1765
await in initSavedRules		
(anonymous)	@	Pagetual.user.js:7515
(anonymous)	@	Pagetual.user.js:1417
Promise.then		
getItem	@	Pagetual.user.js:1417
initRules	@	Pagetual.user.js:7438
init	@	Pagetual.user.js:10303
visibilitychangeHandler	@	Pagetual.user.js:10311

重现步骤

通过排除法感觉是和页面中jspanel4 有冲突。

脚本猫版本

1.0.2

操作系统以及浏览器信息

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36

补充信息 (选填)

No response

Activity

  1. CodFrm commented on Aug 26, 2025

    @CodFrm
    Member

    页面是哪个页面呢?

  2. CodFrm commented on Sep 4, 2025

    @CodFrm
    Member

    没有更多信息,无法复现,先close了

  3. QiWei commented on Sep 8, 2025

    @QiWei
    Author

    重新方法:访问 https://jspanel.de/,创建测试脚本:

    // ==UserScript==
    // @name         New Userscript
    // @namespace    https://bbs.tampermonkey.net.cn/
    // @version      0.1.0
    // @description  try to take over the world!
    // @author       You
    // @match        https://jspanel.de/
    // @grant        GM_addStyle
    // ==/UserScript==
    
    (function() {
        'use strict';
        GM_addStyle(`
            body { background: #f0f0f0; }
            .btn { color: red; }
        `);
        // Your code here...
    })();
  4. CodFrm commented on Sep 8, 2025

    @CodFrm
    Member

    感谢反馈,已复现,我看看

  5. reopened this on Sep 8, 2025
  6. added a commit that references this issue on Sep 8, 2025
  7. CodFrm commented on Sep 8, 2025

    @CodFrm
    Member

    不知道这个网站干了什么,ev instanceof MouseEvent为true,导致脚本猫的一个逻辑错误的,现已修复:https://github.com/scriptscat/scriptcat/actions/runs/17545510510

    let ev=new CustomEvent("test", {
          code:0,
        });
    console.log(ev instanceof CustomEvent, ev instanceof MouseEvent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions