G
G
GamiDPC2020-11-24 20:33:25
Python
GamiDPC, 2020-11-24 20:33:25

Call function in chrome extension from python or from console?

How to call a function in chrome extension from python selenium or from console while on website

Function in extension
function showMessage(text) {
alert( text );
}

and through python or console call this function
showMessage('Hello everyone!')

if called in Console while on the site, it does not see this function, it only sees it if you go to the extension settings page

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Elvis, 2020-11-24
@Dr_Elvis

Inject a function into the page, then you can call it from the console on the page

InjectFunction = function(PageScriptSpace, func) {
    PageScriptSpace.innerHTML += func;
}
PageScriptSpace = document.createElement('script');
InjectFunction(PageScriptSpace, showMessage);
document.querySelector('head').appendChild(PageScriptSpace);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question