GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Added @include with url of active tab by Cerberus-tm · Pull Request #3231 · greasemonkey/greasemonkey

Conversation

@Cerberus-tm

@Cerberus-tm Cerberus-tm commented May 22, 2026

Copy link
Copy Markdown
Contributor

Gets the url of the active tab and adds @include with the url to the template for new scripts. I am new to editing/committing stuff on Github and webextensions, so I hope this works. Better check it just in case.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Cerberus-tm
Added @include with url of active tab
21f557a
Gets the url of the active tab and adds @include with the url to the template for new scripts. I am new to editing/committing stuff on Github and webextensions, so I hope this works. Better check it just in case.
arantius
arantius reviewed May 22, 2026
View reviewed changes
Comment thread src/browser/monkey-menu.js Outdated
let include = '';
let active_tabs = chrome.tabs
.query({'active': true, 'currentWindow': true});
if (active_tabs && active_tabs[0] && active_tabs[0].url) {

@arantius arantius May 22, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd write this simply if (active_tabs[0]?.url)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Cerberus-tm Cerberus-tm May 23, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I wanted to do that, but I was slightly afraid I might have misunderstood something about what happens in JS if you try to access an item in an array that doesn't exist, was afraid of some blocking error so played it extra safe. But then let's do if (active_tabs[0]?.url).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/browser/monkey-menu.js Outdated
let active_tabs = chrome.tabs
.query({'active': true, 'currentWindow': true});
if (active_tabs && active_tabs[0] && active_tabs[0].url) {
include = `// @include ${active_tabs[0].url}\n`;

@arantius arantius May 22, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's probably more common to write a script for a whole site than for just one particular URL?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Cerberus-tm Cerberus-tm May 23, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is true, I thought about that as well; but it is not so rare to want more than just the domain, and deleting the end is much easier for the user than adding it back, was my thought.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/browser/monkey-menu.js Outdated
let active_tabs = chrome.tabs
.query({'active': true, 'currentWindow': true});
if (active_tabs && active_tabs[0] && active_tabs[0].url) {
include = `// @include ${active_tabs[0].url}\n`;

@arantius arantius May 22, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When compatible I'd suggest @match over @include -- and here I think it's compatible.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Cerberus-tm Cerberus-tm May 23, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I wasn't sure how @match behaved, let's do that.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/browser/monkey-menu.js Outdated
// @name ${name}
// @version 1
// @grant none
` + include +

@arantius arantius May 22, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already in a backtick string, so just ${include} ? I suppose that has the chance to leave an empty line? Default to an explicit * if we can't be more specific?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Cerberus-tm Cerberus-tm May 23, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I did it this way because otherwise we'd have to do either a line // @version 1${include} or a line ${include}// @grant none, which seemed a bit clunky.

Explict * sounds like a good idea, I will do that. Let's see if I can figure out how to change the commit request in Github.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Cerberus-tm
Update monkey-menu.js
015a780
arantius
arantius reviewed May 23, 2026
View reviewed changes
Comment thread src/browser/monkey-menu.js Outdated
let r = Math.floor(Math.random() * 900000 + 100000);
let name = _('unnamed_script_RAND', r);
let scriptSource = `// ==UserScript==
let match_url = '*';

@arantius arantius May 23, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, phooey.

  • https://wiki.greasespot.net/Metadata_Block#@match
  • https://developer.chrome.com/docs/extensions/develop/concepts/match-patterns

@match * is not valid. For match it's <all_urls>. (Match syntax is more complicated and I didn't remember it myself.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Cerberus-tm Cerberus-tm May 26, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have checked that. Will switch to <all_urls>.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/browser/monkey-menu.js Outdated
let match_url = '*';
let active_tabs = chrome.tabs
.query({'active': true, 'currentWindow': true});
if (active_tabs[0]?.url) {

@arantius arantius May 23, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accidentally said this in the commit, but a much shorter/more idiomatic form would be:

let match_url = active_tabs[0]?.url || '<all_urls>';

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Cerberus-tm Cerberus-tm May 26, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered it but wasn't 1000% certain how that behaved so I was probably being too safe. Will use that.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Cerberus-tm
Update monkey-menu.js
4e6f205
@arantius
arantius merged commit 8952664 into greasemonkey:master May 27, 2026
@arantius

arantius commented May 27, 2026

Copy link
Copy Markdown
Collaborator

Thanks for contributing!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@arantius arantius added this to the 4.14 milestone May 27, 2026
@Cerberus-tm

Cerberus-tm commented May 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for helping me!

I edited the file in my fork of the repository each time, then pressed the buttons that appeared, to push it to the master branch. I hope the result was the proper way / wasn't inconvenient for others; I don't know how Github works.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

arantius added a commit to arantius/greasemonkey that referenced this pull request May 28, 2026
@arantius
Fix looking up the current tab.
05ea94a
`.tabs.query()` was returning undefined.  Be sure to try/catch as docs say `.getCurrent()` might throw.

Refs greasemonkey#3231
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@arantius arantius arantius left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

4.14

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@Cerberus-tm @arantius
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.