window.location = "...user.js" won't popup GM installing screen in some cases

34 views
Skip to first unread message

Tazz

unread,
Jan 18, 2011, 8:44:25 PM1/18/11
to greasemonkey-users
Hello guys,

I wrote a script including an auto update function which looks like
that (a small truncated version):

GM_registerMenuCommand("Update: SkriptABC'", function ()
{ updateCheck(true); });

function updateCheck(forced) {
if (forced || parseInt(eval(GM_getValue('lastUpdateCheck', '0'))) +
3600000 <= (new Date().getTime())) {
GM_xmlhttpRequest({
method: "HEAD",
headers: {'Cache-Control': 'no-cache'},
url: scriptUrl,
onload: function(r) {
GM_xmlhttpRequest({
method: "GET",
url: some-newUrl,
headers: { 'Cache-Control': 'no-cache' },
onload: function(r) {
var changelog = r.responseText;
if (changelog) {
window.location = "http://some-url.com/xx/
scriptABC.user.js";
//
}
}
});
}
});
}

updateCheck(false); //will executed all the time the scripts get
loaded.

the problem is following. When the update check is executed by
updateCheck(false); and parseInt(eval(GM_getValue('lastUpdateCheck',
'0'))) + 3600000 <= (new Date().getTime()) is true and a chancelog
could be found window.location just loads the script and shows the
source code. It won't open the GM installing code screen.

When I'm using the registerMenuCommand by clicking on the monkey and
selecting the "Update: SkriptABC" menu item the window.location
command shows me the GM installing code screen.

I am using window.location because I don't want to open a new tab by
GM_openInTab and show the url to that userscript.

So is there any workaround? Looks like window.location won't trigger
the installing screen all the time.

Tazz

unread,
Jan 18, 2011, 9:13:20 PM1/18/11
to greasemonkey-users
To demonstrate the issue the code is useless.

A normal script containing this 2 lines is enough demonstrating the
issue:

1. document.location.href = "http://some-url.com/xx/
scriptABC.user.js";
2. GM_registerMenuCommand("Update: SkriptABC'", function ()
{ document.location.href = "http://some-url.com/xx/
scriptABC.user.js"; });

1. line will load the script source code not the GM installing screen
2. line allows you to load the script by opening the GM installing
screen.



Tazz

unread,
Jan 18, 2011, 10:45:44 PM1/18/11
to greasemonkey-users
I can provide more informations concerning this.
document.location.href = "...user.js"; won't trigger GM installation
window if the website is using framesets and the script is just
triggered in one of these frames.

example html code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Test page</title>
</head>

<frameset border="0" bordercolor="white" frameborder="no"
framespacing="0" rows="31,*,">
<frame name="menu" noresize scrolling="no"
src="_menu_content.php">
<frame name="content2" noresize src="main_content.php">

<noframes>
<body bgcolor="#ffffff">
<p></p>
</body>
</noframes>
</frameset>

</html>

GM code:

// ==UserScript==
// @name test update
// @namespace ----
// @include http://*page-url.com/*
// ==/UserScript==

GM_registerMenuCommand("Update: ScriptABC'", function ()
{ window.location.href= "http://another-url.com/scriptABC.user.js });

if (!window.location.toString().match(page-url.com/main_content.php'))
return;

window.location.href= "http://another-url.com/scriptABC.user.js";


It's truncated but it should reproduce the problem I expire.

This script would open the source code instantly into the
main_content.php frame instead of opening the mentioned GM
installation window.
In my view it's a bug. Can someone confirm this?

Anthony Lieuallen

unread,
Jan 19, 2011, 9:09:05 AM1/19/11
to greasemon...@googlegroups.com
On 01/18/11 22:45, Tazz wrote:
> I can provide more informations concerning this.
> document.location.href = "...user.js"; won't trigger GM installation
> window if the website is using framesets and the script is just
> triggered in one of these frames.

Thanks. Bug tracked here:
https://github.com/greasemonkey/greasemonkey/issues/issue/1248

Using "window.top.document" rather than "document" should be a valid
workaround. (Completely untested, though. Reports of success or
failure would be helpful.)

Tazz

unread,
Jan 19, 2011, 12:34:58 PM1/19/11
to greasemonkey-users
window.top.document is exactly what I am looking for. :-) Thank you.

To provide you more details how to reproduce the bug, I've created a
small test environment including the gm script and the html/php
website working with frame-sets.

http://jpeg.sunnybabe.com/GMGoogleGroups/GM_Bug_Demonstration.zip

You just have to extract all files on some (ftp) webserver. Be sure
the bugDemonstration folder has been created.
Open the ./bugDemonstration/gm_bug_demo.user.js to install the script.
Open ./bugDemonstration/GM_bug_demonstration.php to run the testing
environment.

That's all details I can provide so far.
Reply all
Reply to author
Forward
0 new messages