roam-toolkit
roam-toolkit copied to clipboard
How to call functions from console?
That would eliminate the need to add temporary shortcuts just to test stuff.
Can't seem to figure this out. Googling this mostly produce results for non-webpack extensions.
This describes sending messages between extension modules, but that sendMessage
does nothing in the console, even inside the extension context.
Found a way... clumsy but works:
Edited for simpler way
Add a listener to the dispatcher
contentScript
import {createDemo} from '../create-block-demo'
const dispatchMap = new Map([
// ( ... )
['create-block-demo', createDemo],
]);
Now we need access to the tabs API. Regular console doesn't have it, so we need to get it from one of the extension's pages. The most convenient is the popup page (right-click on extension -> inspect popup).
Now query
the roam tab and send a message to it:
chrome.tabs.query({ currentWindow:true, active: true}, tabs => {
chrome.tabs.sendMessage(tabs[0].id,'create-block-demo',console.log)
})