MCPcopy Create free account
hub / github.com/InverseUI/InverseUI-Recorder / initPageCommunication

Function initPageCommunication

util/communication_utils.js:29–62  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27 * Initialize page-to-content communication for Selenium API
28 */
29export function initPageCommunication() {
30 // Set up the event listener for messages from the page
31 window.addEventListener('inverseui-page-to-content', function(event) {
32 if (event.detail && event.detail.action) {
33 const { action, id, data } = event.detail;
34
35 // Map actions to chrome.runtime.sendMessage calls
36 const messageMap = {
37 'startRecording': { message: 'startRecording' },
38 'stopRecording': { message: 'stopRecording' },
39 'recState': { message: 'recState' },
40 'getActions': { message: 'getActions' },
41 'clearActions': { message: 'clearActions' },
42 'setActionFetchOnlyMode': { message: 'setActionFetchOnlyMode', enabled: event.detail.enabled },
43 'getActionFetchOnlyMode': { message: 'getActionFetchOnlyMode' }
44 };
45
46 const message = messageMap[action];
47 if (message) {
48 chrome.runtime.sendMessage(message, function(response) {
49 // Send response back to page
50 const responseEvent = new CustomEvent('inverseui-content-to-page', {
51 detail: {
52 id: id,
53 response: response,
54 error: chrome.runtime.lastError ? chrome.runtime.lastError.message : null
55 }
56 });
57 window.dispatchEvent(responseEvent);
58 });
59 }
60 }
61 });
62}
63
64/**
65 * Initialize background-to-content message listeners

Callers 1

initializeContentScriptFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected