I have a popup.js
file that has a button say Button_p
. On clicking Button_p
, I inject a script inject.js
to a website using
// snap from popup.js
Button_p.addEventListener('click', () => {
func();
});
function func(){
let queryOptions = { active: true, lastFocusedWindow: true };
let [tab] = await chrome.tabs.query(queryOptions);
console.log(tab);
chrome.scripting.executeScript({
target: {tabId: tab.id},
files: ["inject.js"],
world: 'MAIN'
})
.then( <SECTION to FILL> {store the parsedText} )
}
Now the inject.js
creates a textarea and a button Button_D
in the DOM. The target is on clicking Button_D
it parses the text using parseText
function and then return the parsed value parsedText
back to func
of popup.js
.
// snap from inject.js
function Func(){
// 1. Create Textarea
// 2. Create Button_D
Button_D.onclick = parseText;
.
.
.
return parsedText
}
Func()
I think it may need some promise to return from Func
that this <SECTION to FILL> {store the parsedText} )
potion will be filled up with. But I am unable to implement that .
Can anybody help?