Skip to content

[BUG] 顶级窗口改变存储值,iframe窗口会存在获取不到变更后值的情况 #1049

Description

@xFeny

问题描述

https://nkvod.me/play/132836-5-1.html 网站上刷新(F5)页面后,顶级窗口GM_setValue后,iframe 使用 GM_getValue 会发生获取不到变更后的值的情况。

重现步骤

// ==UserScript==
// @name         iframe窗口获取变更后的存储值
// @namespace    https://docs.scriptcat.org/
// @version      0.1.0
// @description  顶级窗口改变存储值,iframe窗口会获取不到变更后的值
// @author       You
// @grant        GM_addValueChangeListener
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_log
// @match        *://*/*
// @run-at       document-end
// ==/UserScript==

(function () {
    'use strict';

    const KEY = "TEST_VALUE_CHANGE";
    const isTopWin = () => window.top === window.self;

    // iframe 获取改变后的值,正常应该全部次数都弹,实际只会弹3-4次
    GM_addValueChangeListener(KEY, (_, oldValue, newValue) => {
        if (!isTopWin()) alert('iframe 窗口:' + JSON.stringify({ oldValue, newValue, host: location.host }))
    });

    // 顶级窗口改变值
    if (isTopWin()) {
        for (let i = 1; i < 10; i++) {
            setTimeout(() => GM_setValue(KEY, `测试数据${Date.now()}`), i * 1000)
        }
    }

})();

脚本猫版本

v1.2.0

操作系统以及浏览器信息

Win10 Chrome 142.0.7444.176

补充信息 (选填)

No response

Activity

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

    P0🚑 需要紧急处理的内容hotfix需要尽快更新到扩展商店

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions