0๐
โ
[Solved]: I used window.postMessage from the webpageA and window.addEventListener on the extension.
Webpage (Vuejs):
window.postMessage({ type: "FROM_PAGE", text: user_details }, "*");
content_script:
window.addEventListener("message", function(event) {
var user_details = event.data.text;
if (event.data.type && (event.data.type == "FROM_PAGE"))
{
{ ... }
chrome.runtime.sendMessage({'message': 'send_1' , 'data': user_details},function(response){ ... }
}
scraping_script:
chrome.runtime.sendMessage({'message':'send_2', 'data': order},function(response){ ... });
background_script:
var user_details;
chrome.extension.onMessage.addListener(function(request, sender, sendResponse){
if(request.message=="send_1")
{
user_details = request.data;
{ ... }
}
else if(request.message=='send_2')
{
send_data = user_details;
{ ...some post request... }
});
So the webpageA sends user_details to the content_script and the content_script sends them to the background script. As soon as the scraper does the scraping from the webpageB, sends the data to the background script. Then the background script does the post request sending the user_details and the scraped data to the webpageA.
Source:stackexchange.com