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

A bug on multiple requires when no semicolon appear on the first script. #595

Closed
maple3142 opened this issue Sep 9, 2018 · 2 comments
Closed

Comments

@maple3142
Copy link

Expected Behavior

No error.

Actual Behavior

image

An error was thrown because of the first script doesn't end with a semicolon.
It seems that Tampermonkey use string concat to evaluate external scripts.

Specifications

  • Chromium: 67.0.3396.99
  • TM: 4.8.5847
  • OS: Windows 10 x64 build 1803

Script

// ==UserScript==
// @name         Bug
// @match        https://example.com/
// @require      https://unpkg.com/xfetch-js@0.0.6/xfetch.js
// @require      https://unpkg.com/gmxhr-fetch@0.0.3/gmxhr-fetch.min.js
// @grant        none
// ==/UserScript==
@derjanb
Copy link
Member

derjanb commented Sep 11, 2018

Tampermonkey will not add separators between requires, because the code author has to be aware of potential issues especially if semicolons are omitted and the code is intended to be included by other scripts.

You can workaround the issue by requiring a script with a single semicolon. :) Reversing the @require statements might also work.

// @require      https://unpkg.com/xfetch-js@0.0.6/xfetch.js
// @require      https://gist.githubusercontent.com/derjanb/2d241de9f54b79871ac00b31ad4d73e9/raw/262c57c88eb36785d496c85519f97f0b0d2df9a5/semicolon.js
// @require      https://unpkg.com/gmxhr-fetch@0.0.3/gmxhr-fetch.min.js

@derjanb derjanb closed this as completed Sep 11, 2018
@maple3142
Copy link
Author

I don't think it should be taken into consideration.
Because normal script loaders(script tag, node require,...) won't concat the script, semicolon should not affect how modules should be evaluated.

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