{"record":{"id":"fc9c3146053ecf2f","repo":"pear-devs/pear-desktop","slug":"duplicated-userscript-calling","errorCode":null,"errorMessage":"Duplicated Userscript Calling","messagePattern":"Duplicated Userscript Calling","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/plugins/performance-improvement/scripts/cpu-tamer/cpu-tamer-by-animationframe.js","lineNumber":36,"sourceCode":"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n*/\n\n/* oxlint-disable */\n\nexport const injectCpuTamerByAnimationFrame = ((__CONTEXT__) => {\n  'use strict';\n\n  const win = this instanceof Window ? this : window;\n\n  // Create a unique key for the script and check if it is already running\n  const hkey_script = 'nzsxclvflluv';\n  if (win[hkey_script]) throw new Error('Duplicated Userscript Calling'); // avoid duplicated scripting\n  win[hkey_script] = true;\n\n  /** @type {globalThis.PromiseConstructor} */\n  const Promise = (async () => { })().constructor; // hacks Promise in WaterFox Classic and \"Promise.resolve(0)\" nevers resolve.\n  const PromiseExternal = ((resolve_, reject_) => {\n    const h = (resolve, reject) => { resolve_ = resolve; reject_ = reject };\n    return class PromiseExternal extends Promise {\n      constructor(cb = h) {\n        super(cb);\n        if (cb === h) {\n          /** @type {(value: any) => void} */\n          this.resolve = resolve_;\n          /** @type {(reason?: any) => void} */\n          this.reject = reject_;\n        }\n      }\n    };\n  })();","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/pear-devs/pear-desktop/blob/1e2aac5706c870c93ed74ba8727ae8390d3b0fa5/src/plugins/performance-improvement/scripts/cpu-tamer/cpu-tamer-by-animationframe.js#L18-L54","documentation":"This userscript (CPU Tamer by AnimationFrame) sets a flag on the window object ('nzsxclvflluv') to prevent running twice in the same page. If the flag is already set — i.e. the script was injected a second time into the same window — it immediately throws 'Duplicated Userscript Calling'.","triggerScenarios":"The script being injected twice into one page: both the app's bundled copy and a manually installed userscript-manager copy; a plugin reinstall injecting again without reload; two different plugins shipping the same script; SPA navigation re-running injection into the same window.","commonSituations":"Installing the CPU Tamer userscript in Tampermonkey while the performance-improvement plugin also injects it; enabling two plugins that both bundle cpu-tamer; stale injection after hot-reload during development.","solutions":["Uninstall/disable the standalone userscript version if the plugin already injects it","Enable only one plugin that ships this script","Reload the page after disabling duplicates so the window flag resets","If you maintain an injector, check for the flag (win.nzsxclvflluv) before injecting"],"exampleFix":"// before\ninjectUserscript(cpuTamerSource); // called on every plugin enable\n\n// after\nif (!(window as any).nzsxclvflluv) injectUserscript(cpuTamerSource);","handlingStrategy":"try-catch","validationCode":"if (!(window as any).nzsxclvflluv) injectUserscript(cpuTamerSrc);","typeGuard":null,"tryCatchPattern":"inject(cpuTamerSrc).catch((e) => { if (!/Duplicated Userscript/.test(e.message)) throw e; });","preventionTips":["Enable only one plugin/variant that ships this script","Remove standalone userscript-manager copies when the plugin injects it","Reload the page after toggling plugins to clear the singleton flag"],"tags":["userscript","duplicate-injection","performance-improvement","cpu-tamer","singleton-guard"],"backgroundTag":"duplicate-script-injection","analyzedSha":"1e2aac5706c870c93ed74ba8727ae8390d3b0fa5","analyzedAt":"2026-08-27T20:01:08.614Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}