Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GM 3.0: GM_openInTab opens tabs relative to active tab, instead of the source tab #2105

Closed
erosman opened this issue Mar 14, 2015 · 11 comments
Closed
Milestone

Comments

@erosman
Copy link

erosman commented Mar 14, 2015

As in the title, I have scripts that open tabs automatically.
In previous versions, the new tab was opened relative to the source tab but now it opens relative to the active tab which results in tabs opening all over the place (for someone like me who always have multiple tabs open)

I just noticed another (rather annoying) development.
GM_openInTab is also setting the new tab as active tab. That happened now when I was typing this and suddenly, I ended up on another page (new tab that was opened)
(browser.tabs.loadInBackground is true)

(PS. I reviewed GM 3.0. Please fix these and I will review it quickly.)

@janekptacijarabaci
Copy link
Contributor

Confirmed.

Ad "inBackground":

!!null == false;

i.e., works incorrectly:
https://github.com/greasemonkey/greasemonkey/blob/master/modules/miscapis.js#L111

  if ('undefined' == typeof aLoadInBackground) aLoadInBackground = null;
  [...]
  return aScriptRunner.openInTab(uri.spec, !!aLoadInBackground);

The suggestion (for example):

  if ('undefined' == typeof aLoadInBackground) aLoadInBackground = null;
  if (aLoadInBackground != null) aLoadInBackground = !!aLoadInBackground;
  [...]
  return aScriptRunner.openInTab(uri.spec, aLoadInBackground);

Also #2106

Ad "relatedToCurrent":

But it does not work well...

In doing so... relatedToCurrent: true

@erosman
Copy link
Author

erosman commented Mar 15, 2015

Where is aLoadInBackground set?
Is it passed to the GM_openInTab?
If it is passed as a parameter, then the following would do
aLoadInBackground = aLoadInBackground || null

If it is supposed to be set elsewhere, then:
aLoadInBackground = typeof aLoadInBackground !== 'undefined' ? aLoadInBackground : null;

Personally, I dislike double negative
return aScriptRunner.openInTab(uri.spec, aLoadInBackground);

@janekptacijarabaci
Copy link
Contributor

I don't know why it's like that. So I changed it this way and works the way I need it.

It is an example of issues to be resolved. Note that there are lots of ways to solve these problems.

@erosman
Copy link
Author

erosman commented Mar 15, 2015

I changed mine to the following which fixes the background issue...

If I knew where it was picking up the tab index (it is picking the active tab index, not the one that initialled the script) ... I would fix that too.

function GM_openInTab(aScriptRunner, aUrl, aLoadInBackground) {

  aLoadInBackground = typeof aLoadInBackground !== 'undefined' ? aLoadInBackground : null;

  // Resolve URL relative to the location of the content window.
  var baseUri = Services.io.newURI(aScriptRunner.window.location.href, null, null);
  var uri = Services.io.newURI(aUrl, null, baseUri);

  return aScriptRunner.openInTab(uri.spec, aLoadInBackground);
}

@arantius arantius added this to the 3.2 milestone Mar 16, 2015
@erosman
Copy link
Author

erosman commented Mar 16, 2015

arantius added this to the 3.2 milestone 3 hours ago

Does that mean it will not be fixed for another 2 versions??!!
It is causing havoc with some of my scripts.
If you point me to where it picks up the active tab, I will try to fix my version for the time being.

@ArtCarnage
Copy link

The tab focus is a big issue for us as well. We have a number of scripts with operations that open from 1 to 10 tabs in the background, perform tasks, then close themselves. Having the tab focus jump around is a huge workflow interruption, and rather confusing. The best possible outcome, as I see it, is for the default mode to be opening in the background, with an optional parameter after the URL, to have the tab grab focus. There have been a few instances where the ability to have the new tab get focus would be preferable, so having the option to do that would make the API for useful.

@janekptacijarabaci
Copy link
Contributor

@ArtCarnage: See #1936.

@erosman
Copy link
Author

erosman commented Mar 20, 2015

I havent noticed any activity on the main GM page here... is anyone working on these issues?!

@Dexmaster
Copy link

There is a problem with version 3.0+ and GM_openInTab() function. Tabs are opened in foreground and not background.
,
There is "browser.tabs.loadInBackground: true" in about:config, but it does not help.

Currently staying with 2.3 version that does not have such problems.

@erosman
Copy link
Author

erosman commented Mar 22, 2015

More info:
The following errors appear in console when opening tab with GM_openInTab

value is not a non-null object tabbrowser.xml:430:0
NS_ERROR_UNEXPECTED: Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsISyncMessageSender.sendSyncMessage] framescript.js:294:0
NS_ERROR_UNEXPECTED: Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsISyncMessageSender.sendSyncMessage] content.js:648:0
NS_ERROR_UNEXPECTED: Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsISyncMessageSender.sendSyncMessage] content-sessionStore.js:178:0

@codespaced
Copy link

Until a fix is issued, you can force GM_openInTab to open tabs in the background GM_openInTab(url, 1) as noted here.

Syntax
function GM_openInTab( url, loadInBackground )

Arguments

  • url
    • (String) The URL to navigate the new tab to
  • loadInBackground
    • (Boolean) Does not focus on the new tab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants