stop tabs from loading

321 views
Skip to first unread message

Moin

unread,
Dec 13, 2010, 7:12:57 AM12/13/10
to Chromium-extensions
I'm trying to stop all tabs from loading when chrome starts up. I then
want to load only the tab I click on.

I was able to do this by using a content script in manifest.json.
{
"name": "blah",
"version": "1.0",
"background_page": "background.html",
"content_scripts": [
{
"matches": ["http:// */*"],
"js": ["stop.js"],
"run_at": "document_start"
}
] ,
"permissions": [
"tabs", "http://*/*"
]
}

stop.js just contains one line -> window.stop();

Now this isn't ideal because, being a content script it stops loading
everytime, including when I click on a tab.

So, I tried doing in in background.html without a content script, but
I can't get it to work:

background.html
-----------------------------

<!doctype html>
<html>
<script>

chrome.tabs.getAllInWindow(null, function stopTabs(tabs) {
for (var i in tabs) {
var tab = tabs[i];
//alert(tab.url);
var stopLoading = {'code': 'window.stop()'}; //alerts work here, but
window.stop doesn't?!!
chrome.tabs.executeScript(tab.id, stopLoading);
}
});

</script>
</html>

Any pointers?

Arne Roomann-Kurrik

unread,
Dec 13, 2010, 5:25:44 PM12/13/10
to Moin, Chromium-extensions
You only want to do this once per launch?  Is this in the case of chrome restarting and restoring a bunch of tabs?

Are you actually getting any tabs in your getAllInWindow call?  The background page will run pretty early, so maybe you're injecting your script too early.  Have you tried running that code in a setTimeout handler?  Try waiting a second or two before stopping the tab load to see if it's just a timing issue.

~Arne



--
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.


Moin

unread,
Dec 13, 2010, 11:32:34 PM12/13/10
to Chromium-extensions
Yes Arne,

Once per launch, when chrome restarts and loads up the tabs from the
last session.

I'm able to get all the tabs in my getAllInWindow call. I tried it
with setTimeout after a second, but still no luck. Have a look:

<!doctype html>
<html>
<script>

function init() {

chrome.tabs.getAllInWindow(null, function stopTabs(tabs) {
for (var i in tabs) {
var tab = tabs[i];
var stopLoading = {'code': 'window.stop()'};
chrome.tabs.executeScript(tab.id, stopLoading);
}
});

}

setTimeout('init()',1000)
//init();

</script>
</html>

Could it be related to this bug report:
http://groups.google.com/a/chromium.org/group/chromium-extensions/browse_thread/thread/ee9d514506aadffd#
?

- Moin

On Dec 14, 2:25 am, Arne Roomann-Kurrik <kur...@chromium.org> wrote:
> You only want to do this once per launch?  Is this in the case of chrome
> restarting and restoring a bunch of tabs?
>
> Are you actually getting any tabs in your getAllInWindow call?  The
> background page will run pretty early, so maybe you're injecting your script
> too early.  Have you tried running that code in a setTimeout handler?  Try
> waiting a second or two before stopping the tab load to see if it's just a
> timing issue.
>
> ~Arne
>
> > 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>
> > .

Scott

unread,
Dec 14, 2010, 10:19:48 AM12/14/10
to Chromium-extensions
You have to wait until after the page _starts_ loading. You could
detect this with the tabs.onUpdate event ("loading" status). But that
won't stop it from loading a bit in the beginning before it gets the
message.

On Dec 13, 10:32 pm, Moin <mmza...@gmail.com> wrote:
> Yes Arne,
>
> Once per launch, when chrome restarts and loads up the tabs from the
> last session.
>
> I'm able to get all the tabs in my getAllInWindow call. I tried it
> with setTimeout after a second, but still no luck. Have a look:
>
> <!doctype html>
> <html>
> <script>
>
>         function init() {
>
>                 chrome.tabs.getAllInWindow(null, function stopTabs(tabs) {
>                   for (var i in tabs) {
>                         var tab = tabs[i];
>                         var stopLoading = {'code': 'window.stop()'};
>                         chrome.tabs.executeScript(tab.id, stopLoading);
>                   }
>                 });
>
>         }
>
>         setTimeout('init()',1000)
>         //init();
>
> </script>
> </html>
>
> Could it be related to this bug report:http://groups.google.com/a/chromium.org/group/chromium-extensions/bro...

Arne Roomann-Kurrik

unread,
Dec 14, 2010, 2:19:21 PM12/14/10
to Scott, Chromium-extensions
Yeah, this is a better answer.  

~Arne

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