douyinWEB/extensions/dylive-helper/src/content-dylive-bridge.js
eric 70fc686ddf feat: X 插件任务通道 poll 演进为 WebSocket
Web 下发即时推送;插件断线自动重连,HTTP poll 仅作兜底。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-15 01:32:13 -05:00

28 lines
833 B
JavaScript

/**
* Auto-pair with dylive web: when user is logged into /x (or any dylive page),
* pull ingest token + origin and hand to the service worker. No manual paste.
*/
(async () => {
try {
const origin = location.origin;
const res = await fetch(`${origin}/api/x2/status`, {
credentials: "include",
headers: { Accept: "application/json" },
});
if (!res.ok) return;
const data = await res.json();
const token = String(data?.ingest_token || "").trim();
if (!token) return;
chrome.runtime.sendMessage({
type: "DYLIVE_X_AUTO_PAIR",
origin,
token,
ingestUrl: `${origin}/api/x2/ingest`,
pollUrl: `${origin}/api/x2/extension/poll`,
wsUrl: `${origin.replace(/^http/i, "ws")}/api/x2/extension/ws`,
});
} catch {
/* not logged in / offline */
}
})();