Reputation: 416
I am trying to fill out a form on an external webpage based on values from a current page when a user clicks the chrome extension I created.
So what I am trying to do is open the page and pass a message first using this from a popup.js file.
chrome.tabs.create({url: "http://localhost:49177/ProDATA/Add.aspx"},function(tab){
chrome.tabs.sendRequest(tab.id, {FirstName: FirstName}, function(response) {
console.log(response.farewell); })
});
Then on the add.aspx page which would be in a different domain as the page the user is located on I try to do this.
//add listener for chrome extension
var FirstName = '';
function LoadEventListener()
{
alert('test');
chrome.runtime.onMessage.addListener(function (request, sender, response) {
FirstName = request.FirstName;
alert(FirstName);
});
}
I load "LoadEventListener" from the body onload event. and the alert "test" shows, therefore it is indeed loading, however I do not see the "FirstName" alert.
Can someone help?
Upvotes: 1
Views: 858
Reputation: 73506
Priviledged chrome.* API won't work by default on web pages in modern Chrome.
The url should be explicitly allowed via "externally_connectable" in the manifest (see that link for code examples).
Or Use tabs.executeScript to inject the DOM access code instead of tabs.sendRequest
.
The doc says that tabs.sendRequest is deprecated since Chrome 33. Use chrome.tabs.sendMessage
instead.
Upvotes: 2