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

Possible solution to avoid the need for a temporary .user.js redirect for installation #2081

Open
tophf opened this issue Jun 5, 2024 · 2 comments

Comments

@tophf
Copy link

tophf commented Jun 5, 2024

Currently when installing from sites like greasyfork, Tampermonkey has to redirect to a temporary URL in order to circumvent the lack of proper redirection in ManifestV3, w3c/webextensions#610.

Looks like a better workaround might be to change the content-type header of .user.js URLs to an html page to prevent Chrome's built-in handling, so instead a normal navigation is performed, which will be seen by a non-blocking webRequest or chrome.tabs.onUpdated or chrome.webNavigation.

chrome.declarativeNetRequest.updateSessionRules({
  removeRuleIds: [1],
  addRules: [{
    id: 1,
    condition: {
      urlFilter: '.user.js|',
      resourceTypes: ['main_frame']
    },
    action: {
      type: 'modifyHeaders',
      responseHeaders: [{header:'content-type', value: 'text/html', operation: 'set'}]
    }
  }]
})

This example only shows one pattern in urlFilter. I don't know what's best for multiple patterns, either several identical rules with different urlFilter or one rule with regexFilter.

@derjanb
Copy link
Member

derjanb commented Jun 28, 2024

Unfortunately this is not a solution because html in userscripts is parsed as such.

@derjanb derjanb closed this as not planned Won't fix, can't repro, duplicate, stale Jun 28, 2024
@tophf
Copy link
Author

tophf commented Jun 28, 2024

It can be prevented by running stop(); in a content script for .user.js at document_start.

@derjanb derjanb reopened this Jun 28, 2024
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

2 participants