roam-toolkit icon indicating copy to clipboard operation
roam-toolkit copied to clipboard

How to call functions from console?

Open dalmo3 opened this issue 5 years ago • 1 comments

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.

dalmo3 avatar Feb 24 '20 12:02 dalmo3

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)  
})

dalmo3 avatar Feb 24 '20 12:02 dalmo3