-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelay.js
More file actions
43 lines (43 loc) · 1.75 KB
/
relay.js
File metadata and controls
43 lines (43 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
(function() {
if (typeof chrome === 'undefined' || !chrome.storage || !chrome.storage.local) return;
var now = Date.now();
chrome.storage.local.set({ bridgeLastPoll: now });
try { chrome.runtime.sendMessage({ action: 'bridgePoll' }); } catch (e) {}
var contextHandler = function(e) {
if (e.data && (e.data.type === 'browserclaw-context-ok' || e.data.type === 'browserclaw-context-wrong')) {
window.removeEventListener('message', contextHandler);
chrome.storage.local.set({ bridgeWrongContext: e.data.type === 'browserclaw-context-wrong' });
}
};
window.addEventListener('message', contextHandler);
try {
window.parent.postMessage({ type: 'browserclaw-context-check' }, '*');
} catch (err) {}
chrome.storage.local.get(['bridgePrompt', 'bridgeNewSession', 'taskInProgress'], function(data) {
var prompt = data && data.bridgePrompt;
if (prompt && window.parent !== window) {
try {
window.parent.postMessage({
type: 'browserclaw-prompt',
prompt: prompt,
newSession: !!(data && data.bridgeNewSession),
}, '*');
} catch (e) {}
chrome.storage.local.remove(['bridgePrompt', 'bridgeNewSession']);
}
if (data && data.taskInProgress && window.parent !== window) {
var doneHandler = function(e) {
if (e.data && e.data.type === 'browserclaw-done') {
window.removeEventListener('message', doneHandler);
try {
chrome.runtime.sendMessage({ action: 'cometResult', responseText: e.data.responseText || '' });
} catch (err) {}
}
};
window.addEventListener('message', doneHandler);
try {
window.parent.postMessage({ type: 'browserclaw-check-done' }, '*');
} catch (err) {}
}
});
})();