Skip to content

Spot it. Save it. Free, local-first Chrome extension for images, videos and prompts. Explore 2,000+ curated cases and connect your library to AI Agents via MCP. 提示词导演

修复工具栏关闭侧栏与内部页误导提示

MigenAI7a64713b23a0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 63fa7f8..b7d22ca 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@
- 智能选图优先真实图片、视频和画布,去除同时包住提示词与按钮的重复外层候选,并按背景图实际绘制区域计算边界。
- 网页采集会预检当前站点权限,按当前来源授权后在同一次操作中继续扫描,并分别提示拒绝授权、站点访问限制、不可注入页面与脚本启动失败。
- 修复侧栏在工具栏图标已授予临时访问权后仍误判当前页不可访问的问题;授权状态会在同一次采集操作中重新读取并继续申请当前网站权限。
+- 工具栏图标改为只打开或保持侧栏,不再把已打开的侧栏切换关闭;Chrome 新标签页等内部页面会明确说明不可采集,普通网页仍可继续智能选图。
## 1.18.8
diff --git a/background.js b/background.js
index b5ba554..48a9aca 100644
--- a/background.js
+++ b/background.js
@@ -217,6 +217,7 @@ import {
sourceContextForUrl
} from "./capture-draft.js";
import { createCaptureWorkspace } from "./capture-workspace.js";
+import { RESTRICTED_PAGE_MESSAGE } from "./capture-permissions.js";
import {
applyPageCaptureSelections,
combinePageCaptureCandidates,
@@ -418,7 +419,7 @@ const captureRuntime = createCaptureWorkspace({
chrome.runtime.onInstalled.addListener(async () => {
await restrictLocalStorageAccess();
await syncContextMenus();
- await chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: true });
+ await chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: false });
const state = await readState();
await commitLocalChanges({ [STORAGE_KEYS.settings]: state.settings });
@@ -427,7 +428,7 @@ chrome.runtime.onInstalled.addListener(async () => {
restrictLocalStorageAccess().catch((error) => console.error("PromptDirector storage access restriction failed", error));
syncContextMenus().catch((error) => console.error("PromptDirector context menu sync failed", error));
-chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: true }).catch((error) => console.error("PromptDirector side panel setup failed", error));
+chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: false }).catch((error) => console.error("PromptDirector side panel setup failed", error));
chrome.alarms.onAlarm.addListener((alarm) => {
if (alarm.name === LIBRARY_MAINTENANCE_ALARM) scheduleLibraryMaintenanceRunner();
if (alarm.name === AUTOMATIC_VISION_ALARM) scheduleAutomaticVisionRunner();
@@ -457,6 +458,12 @@ chrome.commands.onCommand.addListener(async (command) => {
await showResultToast(tab?.id, response.message, !response.ok);
});
+chrome.action.onClicked.addListener((tab) => {
+ if (!Number.isInteger(tab?.windowId)) return;
+ chrome.sidePanel.open({ windowId: tab.windowId })
+ .catch((error) => console.error("PromptDirector toolbar side panel open failed", error));
+});
+
chrome.runtime.onConnect.addListener((port) => {
if (port.name !== "capture-region") return;
port.onMessage.addListener(() => undefined);
@@ -909,7 +916,7 @@ async function captureWorkspace() {
async function startPageCapture(mode = "loaded", targetCountValue = 0) {
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
if (!tab?.id || !/^https?:/iu.test(tab.url || "")) {
- return { ok: false, message: "请先切换到需要采集的普通网页" };
+ return { ok: false, message: RESTRICTED_PAGE_MESSAGE };
}
await clearPageCaptureMarkers(tab.id, true).catch(() => undefined);
const sessionId = crypto.randomUUID();
diff --git a/capture-permissions.js b/capture-permissions.js
index 7863a0d..473a894 100644
--- a/capture-permissions.js
+++ b/capture-permissions.js
@@ -1,11 +1,12 @@
export const CONTINUOUS_CAPTURE_ORIGINS = Object.freeze(["<all_urls>"]);
export const CLIPBOARD_READ_PERMISSIONS = Object.freeze(["clipboardRead"]);
+export const RESTRICTED_PAGE_MESSAGE = "当前页不可采集:Chrome 新标签页、设置页和扩展页不允许读取;普通网站请先点工具栏图标。";
const CLIPBOARD_IMAGE_MIME_TYPES = Object.freeze(["image/png", "image/jpeg", "image/webp"]);
export function pagePermissionPattern(pageUrl) {
const url = new URL(String(pageUrl ?? ""));
if (!["http:", "https:"].includes(url.protocol)) {
- throw new Error("请先切换到需要采集的普通网页");
+ throw new Error(RESTRICTED_PAGE_MESSAGE);
}
return `${url.origin}/*`;
}
diff --git a/capture-workspace.js b/capture-workspace.js
index de58c1d..53ab5c3 100644
--- a/capture-workspace.js
+++ b/capture-workspace.js
@@ -20,7 +20,8 @@ import {
import { createTextCandidate } from "./capture-text-candidate.js";
import {
ensureContinuousCapturePermission,
- ensurePagePermission
+ ensurePagePermission,
+ RESTRICTED_PAGE_MESSAGE
} from "./capture-permissions.js";
import { translateForLocale } from "./i18n.js";
import { normalizeUiPreferences, resolveLocale } from "./preferences.js";
@@ -66,7 +67,7 @@ export async function runCaptureTransaction({
const tab = (await chromeApi.tabs.query({ active: true, currentWindow: true }))[0];
if (!tab?.id || !isHttpPage(tab.url)) {
- throw new Error("请先切换到需要采集的普通网页");
+ throw new Error(RESTRICTED_PAGE_MESSAGE);
}
if (!capturesVisual) {
@@ -648,7 +649,7 @@ export function createCaptureWorkspace({
if (!active?.id || (tabId && active.id !== Number(tabId))) {
throw new Error("当前网页已经切换,请重新发起采集");
}
- if (!isHttpPage(active.url)) throw new Error("请在普通网页点击扩展图标后再采集");
+ if (!isHttpPage(active.url)) throw new Error(RESTRICTED_PAGE_MESSAGE);
return active;
}
diff --git a/collector.js b/collector.js
index cc2c096..350e561 100644
--- a/collector.js
+++ b/collector.js
@@ -13,6 +13,7 @@ import {
inspectPagePermission,
pageCapturePermissionFailureMessage,
readClipboardContentAfterFocus,
+ RESTRICTED_PAGE_MESSAGE,
resolveActivePage
} from "./capture-permissions.js";
import { initializeUi, t } from "./i18n.js";
@@ -1093,7 +1094,7 @@ async function startPageCapture(mode, button) {
if (!tab?.url && Number.isInteger(tab?.id)) {
throw new Error(t("Chrome 不会在点击插件图标时弹出授权窗口。请先在当前网页点击工具栏里的 PromptDirector 图标,再回到侧栏点击“授权当前网站并扫描”;待保存内容没有改变。"));
}
- if (!tab?.url) throw new Error(t("请先切换到需要采集的普通网页"));
+ if (!tab?.url) throw new Error(t(RESTRICTED_PAGE_MESSAGE));
let permission = await inspectPagePermission(tab.url, chrome.permissions);
if (permission.status === "missing") {
if (!await ensurePagePermission(tab.url, chrome.permissions)) {
diff --git a/i18n.js b/i18n.js
index 70ee400..650e606 100644
--- a/i18n.js
+++ b/i18n.js
@@ -258,6 +258,7 @@ const EN = Object.freeze({
"+ 点插件图标后再采集": "+ Click the extension icon, then capture",
"Chrome 不会在点击插件图标时弹出授权窗口。请先在当前网页点击工具栏里的 PromptDirector 图标,再回到侧栏点击“授权当前网站并扫描”;待保存内容没有改变。": "Chrome does not show a permission prompt when you click the extension icon. Click the PromptDirector toolbar icon on the current page, then return to the side panel and click Allow this site and scan. Unsaved content was not changed.",
"Chrome 内部页、扩展页或本机设置页不能采集,请切换到普通网页": "Chrome internal pages, extension pages, and browser settings cannot be captured. Switch to a regular web page.",
+ "当前页不可采集:Chrome 新标签页、设置页和扩展页不允许读取;普通网站请先点工具栏图标。": "This page cannot be captured. Chrome new tabs, settings, and extension pages cannot be read. On a regular website, click the toolbar icon first.",
"你没有授予当前网站访问权限。请再次点击“授权当前网站并扫描”,或在 Chrome 扩展详情的“网站访问权限”中允许此网站;待保存内容没有改变。": "Access to this site was not granted. Click Allow this site and scan again, or allow this site under the extension's Site access settings. Unsaved content was not changed.",
"媒体域名权限未获授权;仍会保存正文和可用引用,并逐项显示下载失败原因。": "Media-domain access was not granted. Text and usable references will still be saved, with download failures shown per item.",
"网页内容保存失败": "Web content could not be saved",
diff --git a/store/CHROME_WEB_STORE_SUBMISSION.md b/store/CHROME_WEB_STORE_SUBMISSION.md
index 07ac47a..b4d6f3e 100644
--- a/store/CHROME_WEB_STORE_SUBMISSION.md
+++ b/store/CHROME_WEB_STORE_SUBMISSION.md
@@ -7,8 +7,8 @@ This file is the source-of-truth worksheet for the current PromptDirector manife
- Chrome Web Store item public key: stored in the source `manifest.json` for local identity verification only; `package:release` removes `key` from the upload manifest.
- Expected extension ID: `iahakaahijddcjjldidbclicedibgpjm`.
- Current release candidate: `dist/PromptDirector-1.18.9.zip`.
-- Candidate size: `8,139,589` bytes.
-- Candidate SHA-256: `162523728f58b22000697b6ba8b5c3d2a72d32f8780a09c59086429598c21631`.
+- Candidate size: `8,140,293` bytes.
+- Candidate SHA-256: `7a6471d13aea3f279577803b5672f91b80d85feaea6acfb87d83a5d7b2bb09ad`.
- Generate a candidate only with `npm run package:release`; the command verifies the source public key against the expected identity, then removes `key` from the Web Store upload manifest.
## Store listing
diff --git a/test/capture-permission-flow.test.js b/test/capture-permission-flow.test.js
index da82e7c..77e4866 100644
--- a/test/capture-permission-flow.test.js
+++ b/test/capture-permission-flow.test.js
@@ -13,6 +13,7 @@ import {
inspectPagePermission,
pageCapturePermissionFailureMessage,
pagePermissionPattern,
+ RESTRICTED_PAGE_MESSAGE,
resolveActivePage
} from "../capture-permissions.js";
import { runCaptureTransaction } from "../capture-workspace.js";
@@ -178,7 +179,7 @@ test("text collection keeps its narrower per-site permission", async () => {
["request", { origins: ["https://example.com/*"] }]
]);
await assert.rejects(() => ensurePagePermission("chrome://extensions", permissions), {
- message: "请先切换到需要采集的普通网页"
+ message: RESTRICTED_PAGE_MESSAGE
});
});
@@ -299,6 +300,15 @@ test("page capture requests only the current site and continues in the same clic
assert.match(flow, /你没有授予当前网站访问权限/);
});
+test("toolbar authorization keeps the side panel open instead of toggling it closed", async () => {
+ const source = await readFile(new URL("background.js", projectRoot), "utf8");
+ assert.doesNotMatch(source, /openPanelOnActionClick:\s*true/);
+ assert.match(source, /chrome\.action\.onClicked\.addListener/);
+ const listenerStart = source.indexOf("chrome.action.onClicked.addListener");
+ const listenerEnd = source.indexOf("chrome.runtime.onConnect.addListener", listenerStart);
+ assert.match(source.slice(listenerStart, listenerEnd), /chrome\.sidePanel\.open\(\{\s*windowId:\s*tab\.windowId\s*\}\)/);
+});
+
test("creative result capture and commit use one background transaction", async () => {
const messages = [];
const capturedDraft = { id: "captured", visuals: [{ id: "visual-1" }] };
diff --git a/test/capture_and_cross_page_e2e.py b/test/capture_and_cross_page_e2e.py
index de4a251..fa938e4 100644
--- a/test/capture_and_cross_page_e2e.py
+++ b/test/capture_and_cross_page_e2e.py
@@ -8,6 +8,8 @@ from e2e_support import extension_session
def main() -> None:
with extension_session("prompt-director-capture-") as session:
collector = session.open_page("collector.html")
+ panel_behavior = collector.evaluate("async () => chrome.sidePanel.getPanelBehavior()")
+ assert panel_behavior.get("openPanelOnActionClick") is False
collector.evaluate(
"""async () => chrome.runtime.sendMessage({
type: 'UPDATE_CAPTURE_DRAFT',
@@ -70,7 +72,7 @@ def main() -> None:
library.locator("#start-compose").click()
expect(library).to_have_url(f"chrome-extension://{session.extension_id}/composer.html")
assert len(session.context.pages) == internal_page_count
- print({"capture": "passed", "source_pages": len(saved["sourcePages"]), "library_full_tab": True, "internal_navigation": "same-tab"})
+ print({"capture": "passed", "toolbar_keeps_panel_open": True, "source_pages": len(saved["sourcePages"]), "library_full_tab": True, "internal_navigation": "same-tab"})
if __name__ == "__main__":