紧急修正: GM.delete/setValue Promise不fulfill#865
Merged
CodFrm merged 7 commits intoscriptscat:mainfrom Oct 21, 2025
Merged
Conversation
Member
|
一个可复现的脚本: // ==UserScript==
// @name New Userscript T0Z1-1
// @namespace https://docs.scriptcat.org/
// @version 0.1.0
// @description try to take over the world!
// @author You
// @match https://github.com/scriptscat/scriptcat/pull/865
// @icon https://www.google.com/s2/favicons?sz=64&domain=github.com
// @grant GM.setValue
// @grant GM.deleteValue
// ==/UserScript==
(function () {
'use strict';
GM.deleteValue('test1').then(() => {
console.log("delete ok");
});
GM.setValue('test1', undefined).then(() => {
console.log('set ok');
});
// 变量值没变
GM.setValue('test2', 1).then(() => {
console.log('set test2 ok');
GM.setValue('test2', 1).then(() => {
console.log('set2 test2 ok');
});
});
// Your code here...
})(); |
Contributor
There was a problem hiding this comment.
Pull Request Overview
此PR修复了 GM.deleteValue 和 GM.setValue 方法在值未实际更新时 Promise 不会 fulfill 的关键 bug。主要更改包括:
- 添加
valueUpdated标志来追踪值是否实际更新 - 确保即使值未改变也发送消息以 fulfill Promise
- 在 content script 中只在值实际更新时处理值变更
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/app/service/service_worker/value.ts | 添加 valueUpdated 标志并修复了一个 bug (使用错误的变量引用 config![tabKey][key].default);无条件发送消息确保 Promise fulfill |
| src/app/service/service_worker/value.test.ts | 更新测试以验证 valueUpdated 标志在各种场景下的行为 |
| src/app/service/service_worker/runtime.ts | 添加条件判断,仅在值实际更新时更新早期启动脚本 |
| src/app/service/queue.ts | 在 TScriptValueUpdate 类型中添加 valueUpdated 字段 |
| src/app/service/content/types.ts | 在 ValueUpdateDataEncoded 类型中添加 valueUpdated 字段 |
| src/app/service/content/gm_api.ts | 在 valueUpdate 方法中添加条件判断,仅在值实际更新时处理值变更逻辑 |
| src/app/service/content/gm_api.test.ts | 更新测试以包含 valueUpdated 字段并改进测试覆盖率 |
| src/app/repo/scripts.ts | 使用 Partial<Record<>> 改进 UserConfig 类型定义的类型安全性 |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Collaborator
Author
|
@CodFrm 这个bug有明显影响脚本操作。可以的话先发个Beta版。 |
Member
|
@cyfung1031 上一个版本的edge的审核还没给我过,我在等edge审核过了再发 |
Collaborator
Author
Edge 1.2.0.1300 了 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
合并后请发布新Beta版
之前没考虑 deleteValue 时,value 本身就是undefined, 因此 GM.deleteValue(xxx) 不会 Promise fulfill
现在没值更新也是发消息。
收消息那边处理