Skip to content

Commit

Permalink
Improve script error reporting.
Browse files Browse the repository at this point in the history
By putting line one of the user script on line one of the generated eval content.
  • Loading branch information
arantius committed Jul 25, 2017
1 parent bf1185c commit 4b34c3e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/user-script-obj.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,17 @@ window.EditableUserScript = class EditableUserScript
get requiresContent() { return _safeCopy(this._requiresContent); }

calculateEvalContent() {
// Put the first line of the script content on line one of the
// generated content -- wrapped in a function. Then add the rest
// of the generated parts.
this._evalContent
= 'try {\n\n'
+ '(function(){\n'
= 'try {'
+ '(function scopeWrapper(){'
+ 'function userScript(){' + this._content + '} // User Script End.\n\n'
+ this.calculateGmInfo() + '\n\n'
+ (apiProviderSource && (apiProviderSource(this) + '\n\n') || '')
+ apiProviderSource(this) + '\n\n'
+ Object.values(this._requiresContent).join('\n\n')
+ this._content + '\n\n'
+ '})();\n\n'
+ 'userScript();})();\n\n' // Ends scope wrapper.
+ '} catch (e) { console.error("Script error: ", e); }\n\n'
+ '//# sourceURL=user-script:' + escape(this.id);
}
Expand Down

0 comments on commit 4b34c3e

Please sign in to comment.