Skip to content

Auto-detection of GM_ APIs breaks use of GM_config w/ Tampermonkey #10

@darkrain42

Description

@darkrain42

Upgrading from rollup-plugin-userscript 0.3.7 to 1.0.0 breaks a userscript that uses GM_config when the user-script is injected in Tampermonkey due to the auto-detection of "GM_" APIs (#9). (It appears to work OK in Firefox Developer Edition + Violentmonkey).

The resulting userscript block looks similar to:

// ==UserScript==
// @name        Example
// @version     1
// @author      example
// @match       https://example.com
// @sandbox     JavaScript
// @run-at      document-start
// @require     https://raw.githubusercontent.com/sizzlemctwizzle/GM_config/06f2015c04db3aaab9717298394ca4f025802873/gm_config.js#sha256=c8f95a548ad83bcc8d82d5c17b1cc76f953ef831a00ff94514ed5b7b76f75d91
// @grant       GM.getValue
// @grant       GM.info
// @grant       GM.setValue
// @grant       GM_addStyle
// @grant       GM_config
// @grant       GM_getValue
// @grant       GM_info
// @grant       GM_setValue
// @grant       unsafeWindow
// ==/UserScript==

rollup-plugin-userscript automatically added the GM_config grant. When TM tries to inject the userscript into a page, it errors out:

  • Chrome: Uncaught SyntaxError: Failed to execute 'appendChild' on 'Node': Identifier 'GM_config' has already been declared (at userscript.html?name=[...]:51:5)
  • Firefox: Uncaught SyntaxError: redeclaration of formal parameter GM_config

I can work around this in the rollup config, but it's ugly:

      userscript((meta) =>
        meta
          .replace(/^\/\/ @grant +GM_config\n/m, '')
          .replace('process.env.VERSION', pkg.version)
          .replace('process.env.AUTHOR', pkg.author);
      ),

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions