src/PopupWindow.js
// send a message to the content script
send a message to the content script
send a message to the content script
async function sendMessage(type, data, showError, callback) {
		const tab = await waitFor(() => tabRef.current);
		if (!window.chrome || !window.chrome.tabs || !tab) {
			return;
		}
		window.chrome.tabs.executeScript(
			tab.id,
			{ file: 'content_script.js' },
			() =>
				window.chrome.tabs.sendMessage(
					tab.id,
					{ type: type, data: data },
					(response) => {
						if (response && response.errorMessage) {
							showError(response.errorMessage);
							return;
						}
						if (callback) {
							callback(response);
						}
					}
				)
		);
	}
async function sendMessage ( type , data , showError , callback ) { const tab = await waitFor ( ( ) => tabRef . current ) ; if ( ! window . chrome || ! window . chrome . tabs || ! tab ) { return ; } window . chrome . tabs . executeScript ( tab . id , { file : 'content_script.js' } , ( ) => window . chrome . tabs . sendMessage ( tab . id , { type : type , data : data } , ( response ) => { if ( response && response . errorMessage ) { showError ( response . errorMessage ) ; return ; } if ( callback ) { callback ( response ) ; } } ) ) ; }
send a message to the content script
send a message to the content script
// this is pretty limited in use as page.js can't return anything