Skip to content

Solution to userscript not refreshing on every page load #63

@testuser3158

Description

@testuser3158

Hi,

Even with the use of proxy script and setting Tampermonkey's externals update interval to always, I noticed the old version of script would remain active for one or two page reloads. It seems like common problem so I'll leave my solution here, in case it's of use for someone.

  1. In Tampermonkey's extension details page over at chrome://extensions/?id=dhdgffkkebhmkfjojejmpbldmpobfkfo, enable "Allow access to file URLs"

  2. Use this webpack configuration:

    devServer: {
      static: path.resolve(__dirname, 'dist'),
      devMiddleware: { writeToDisk: true }
    },
    plugins: [
      new WebpackUserscript({
        proxyScript: {
          baseUrl: `file://${path.resolve(__dirname, dist)}`,
          filename: '[basename].proxy.user.js',
          enable: !isProductionBuild
        }
      })
    ]

The important bits are that we make webpack dev server write updated script to disk, so that Tampermonkey can access it with the @require header that now points to file:// instead of the webpack dev server.

Full configuration example here: https://github.com/testuser3158/ylis-suodatin/blob/master/webpack.config.js

Related:

Lastly, thanks @momocow for this great plugin.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions