Tampermonkey / tampermonkey

Tampermonkey is the most popular userscript manager, with over 10 million users. It's available for Chrome, Microsoft Edge, Safari, Opera Next, and Firefox.
GNU General Public License v3.0
4.2k stars 418 forks source link

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

Open tophf opened 4 months ago

tophf commented 4 months ago

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, https://github.com/w3c/webextensions/issues/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 commented 3 months ago

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

tophf commented 3 months ago

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