2010/1/6 Rafael Weinstein <[email protected]> > Tabs created with the extensions.tabs api should be no different from > user-navigated tabs WRT content script injection. If you've setup your > match pattern properly, the content script will be injected. > > One potential problem with the above code is that you are firing the > request when the tab is created, but it still has work to do with > loading, so you may have a race. >
I think there are some race condition because it only work if the target is _blank. > > One option would be to listen to tabs.onUpdated, and wait for > status="complete". > But I want to be informed and do something on the new tab as soon as it is created. > A better approach would be to have the content script contact the > background page. This gets around the timing issue of when the page is > ready. > > But how can the content script know if it is in a new tab ? In fact I want to know if a new renderer process is used. > Not sure what your use case is. Hope this helps. > > Thanks. > On Tue, Jan 5, 2010 at 4:42 PM, Erek Speed <[email protected]> wrote: > > When you create a new tab manually, it is not in your content-script > > match pattern so it probably doesn't get the message. > > > > If you set up the new tab to open a webpage it would probably work. > > > > On Wed, Jan 6, 2010 at 9:04 AM, hok <[email protected]> wrote: > >> Hi, > >> I took the simple example from Message Passing tutotial: > >> http://code.google.com/chrome/extensions/messaging.html > >> > >> I want to send a request to an newly created tab, so the > >> background.html create a tabs.onCreated Listener, and send a request > >> to the tab: > >> > >> background.html > >> =============== > >> chrome.tabs.onCreated.addListener(function(tab) { > >> chrome.tabs.sendRequest(tab.id, {greeting: "hello"}, function > >> (response) { > >> console.log(response.farewell); > >> }); > >> }); > >> > >> in the contentscript.js, there is an Request Listener: > >> > >> contentscript.js > >> ================ > >> chrome.extension.onRequest.addListener( > >> function(request, sender, sendResponse) { > >> console.log(sender.tab ? > >> "from a content script:" + sender.tab.url : > >> "from the extension"); > >> if (request.greeting == "hello") > >> sendResponse({farewell: "goodbye"}); > >> else > >> sendResponse({}); // snub them. > >> }); > >> > >> But it doesn't seem to work, the only time it work is when a click a > >> link like that: > >> <a href="http://example.com" target=_blank>cool</a> > >> not when I click to a new tab. > >> > >> Thanks. > >> > >> -- > >> You received this message because you are subscribed to the Google > Groups "Chromium-extensions" group. > >> To post to this group, send email to > [email protected]. > >> To unsubscribe from this group, send email to > [email protected]<chromium-extensions%[email protected]> > . > >> For more options, visit this group at > http://groups.google.com/group/chromium-extensions?hl=en. > >> > >> > >> > >> > > > > -- > > You received this message because you are subscribed to the Google Groups > "Chromium-extensions" group. > > To post to this group, send email to > [email protected]. > > To unsubscribe from this group, send email to > [email protected]<chromium-extensions%[email protected]> > . > > For more options, visit this group at > http://groups.google.com/group/chromium-extensions?hl=en. > > > > > > > > >--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/chromium-extensions?hl=en.
