chrome.tabs.update and wait till it's loaded before executeScript will not work for me

11,083 views
Skip to first unread message

eadatepe

unread,
May 30, 2010, 7:04:36 PM5/30/10
to Chromium-extensions
hello chromium-coder,

i want to change the location with chrome.tabs.update and if it's
complete i want exectue a script.
i try it with chrome.tabs.onUpdated, but this function fires it
constantly.
this is my current working solution, but i don't like it.
setTimeout('chrome.tabs.executeScript(null,{file:"script.js"});',
1000);

has someone has a better idea?

many thx

Mohamed Mansour

unread,
May 30, 2010, 10:38:45 PM5/30/10
to eadatepe, Chromium-extensions
Hello, the chrome.tabs.update has a callback parameter, does that help?

chrome.tabs.create({'url': 'http://chromium.org'}, function(tab) {
  console.log('Tab Created ' + tab.id);
});

-
Mohamed Mansour
m...@chromium.org



--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


eadatepe

unread,
May 31, 2010, 7:11:18 AM5/31/10
to Chromium-extensions
Hello,

tabs.update has no status callback if it's loading or complete.
i want to go back to the parent directory of an image url
now i must wait a moment till the site is loading before i execute a
script

here is the complete working source:
http://pastie.org/private/vxefacdfk1kdquewzr7hxa

best regards


On 31 Mai, 04:38, Mohamed Mansour <m0.interact...@gmail.com> wrote:
> Hello, the chrome.tabs.update has a callback parameter, does that help?http://code.google.com/chrome/extensions/tabs.html#method-create
>
> <http://code.google.com/chrome/extensions/tabs.html#method-create>
> chrome.tabs.create({'url': 'http://chromium.org'}, function(tab) {
>   console.log('Tab Created ' + tab.id);
>
> });
>
> -
> Mohamed Mansour
> m...@chromium.org
>
>
>
> On Sun, May 30, 2010 at 7:04 PM, eadatepe <eadat...@gmail.com> wrote:
> > hello chromium-coder,
>
> > i want to change the location with chrome.tabs.update and if it's
> > complete i want exectue a script.
> > i try it with chrome.tabs.onUpdated, but this function fires it
> > constantly.
> > this is my current working solution, but i don't like it.
> > setTimeout('chrome.tabs.executeScript(null,{file:"script.js"});',
> > 1000);
>
> > has someone has a better idea?
>
> > many thx
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Chromium-extensions" group.
> > To post to this group, send email to chromium-extensi...@chromium.org.
> > To unsubscribe from this group, send email to
> > chromium-extensions+unsubscr...@chromium.org<chromium-extensions%2Bunsubscr...@chromium.org>
> > .

Antony Sargent

unread,
Jun 1, 2010, 4:36:45 PM6/1/10
to eadatepe, Chromium-extensions
Try adding a listener for chrome.tabs.onUpdated:



To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.

eadatepe

unread,
Jun 1, 2010, 6:59:37 PM6/1/10
to Chromium-extensions
Hmmm...
chrome.tabs.onUpdated is an event and i can't check it once cause it
fires constantly.

>>>>>>>>>>>>
chrome.browserAction.onClicked.addListener(function(tab) {

// find parent dir
var findpardir = tab.url.lastIndexOf("/");
var pardirurl = tab.url.substr(0,findpardir+1);
// find location ext
var lochref = tab.url.split(".");
var lochrefend = lochref[lochref.length-1].toLowerCase();

if ((lochrefend == 'jpg') || (lochrefend == 'jpeg')) {

chrome.tabs.getSelected(null,function(tab) {
chrome.tabs.update(tab.id,{url:pardirurl});
});

// starts in 1 sec. (then the page loaded probably)
// but i will wait/check if it's complete
setTimeout('chrome.tabs.executeScript(null,{file:"script.js"});',
1000);
}

else {
chrome.tabs.executeScript(null,{file:"script.js"});
}
});
> > <chromium-extensions%2Bunsubscr...@chromium.org<chromium-extensions%252Bunsubscr...@chromium.org>

Antony Sargent

unread,
Jun 1, 2010, 7:17:00 PM6/1/10
to eadatepe, Chromium-extensions
Here's some pseudocode that illustrates what I was thinking:

var tab_callbacks = {};

chrome.tabs.onUpdated.addListener(function(tabid, info, tab) {
  if (info.status != "complete") {
    return;
  }
  if (tab_callbacks[tabid]) {
    tab_callbacks[tabid]();
    delete tab_callbacks[tabid];
  }
});

if (/* we want to update the selected tab now*/) {
  chrome.tabs.getSelected(null, function(tab) {
    tab_callbacks[tab.id] = function() {
      console.log("tab finishing loading now");
      // do other stuff here...
    };
    chrome.tabs.update(tab.id,{url:pardirurl});
  });
});



To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
Reply all
Reply to author
Forward
0 new messages