Posts

Showing posts with the label google-chrome-extension

sending message to chrome extension from a web page

Image
sending message to chrome extension from a web page I want to send message from the console of the random web page to my chrome extension. chrome.extension.sendMessage doesn't seem to work. 5 Answers 5 According to the official docs you should use postMessage in the sender and message event listener in the receiver. postMessage message Here is an example: Your website's page.html var data = { type: "FROM_PAGE", text: "Hello from the webpage!" }; window.postMessage(data, "*"); Content script: (injected using chrome.tabs.executeScript(tabid, {code:... ) chrome.tabs.executeScript(tabid, {code:... window.addEventListener("message", function(event) { // We only accept messages from ourselves if (event.source != window) return; if (event.data.type && (event.data.type == "FROM_PAGE")) { console.log("Conten...

get all links in chrome extension

get all links in chrome extension I'm trying to make an extension that collecting social networks links from the web page where user is. So when user clicking button getLinks we get all links and then by checking condition passing them in the blocks of the extension. I tried to use chrome.tabs.executeScript , and get links through urls = $$('a'); but it's not working getLinks chrome.tabs.executeScript urls = $$('a'); $('#getLinks').click(function(e) { var allLinks = ; var i = 0; chrome.tabs.executeScript( null, {"code": "urls = $$('a'); for (url in urls) { allLinks[i]=urls[url].href; i++;}"}, function() { var vk; var facebook; var linkedin; for (var i=0; i<allLinks.length; i++) { var profil = (allLinks[i].href); if(profil.indexOf('vk.com')!=-1) { vk = profil; $('#vk').text(vk); ...

Access cookies in browser action (chrome extension)?

Access cookies in browser action (chrome extension)? I have browser_action.html which includes browser_action.js . browser_action.html browser_action.js I'm trying to create an ajax request which includes cookies which are already stored for the domain I'm making a request to (I'm basically piggy backing off the login cookie which is encrypted etc). The user is expected to log into the app separately. When it sends the ajax though, it's blank when sending cookies. Thanks Edit Simply adding it to manifest.json doesnt work. manifest.json $.post('http://localhost:3000/dashboard/ext', { active_tab_url: activeTabUrl }).done(function(resp) { ... }).fail(function(jqXHR) { ... }); Possible duplicate of Send XHR request from Chrome extension with cookies – wOxxOm Jul 1 at 4:29 ...