{"record":{"id":"75d0daf1964602d8","repo":"mozilla/pdf.js","slug":"first-argument-of-app-setinterval-must-be-a-string","errorCode":null,"errorMessage":"First argument of app.setInterval must be a string","messagePattern":"First argument of app\\.setInterval must be a string","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/scripting_api/app.js","lineNumber":615,"sourceCode":"    this._document.obj._userActivation = false;\n\n    if (cQuestion && typeof cQuestion === \"object\") {\n      cDefault = cQuestion.cDefault;\n      cQuestion = cQuestion.cQuestion;\n    }\n    cQuestion = (cQuestion || \"\").toString();\n    cDefault = (cDefault || \"\").toString();\n    return this._externalCall(\"prompt\", [cQuestion, cDefault || \"\"]);\n  }\n\n  setInterval(cExpr, nMilliseconds = 0) {\n    if (cExpr && typeof cExpr === \"object\") {\n      nMilliseconds = cExpr.nMilliseconds || 0;\n      cExpr = cExpr.cExpr;\n    }\n\n    if (typeof cExpr !== \"string\") {\n      throw new TypeError(\"First argument of app.setInterval must be a string\");\n    }\n    if (typeof nMilliseconds !== \"number\") {\n      throw new TypeError(\n        \"Second argument of app.setInterval must be a number\"\n      );\n    }\n    const callbackId = this._registerTimeoutCallback(cExpr);\n    this._externalCall(\"setInterval\", [callbackId, nMilliseconds]);\n    return this._registerTimeout(callbackId, true);\n  }\n\n  setTimeOut(cExpr, nMilliseconds = 0) {\n    if (cExpr && typeof cExpr === \"object\") {\n      nMilliseconds = cExpr.nMilliseconds || 0;\n      cExpr = cExpr.cExpr;\n    }\n\n    if (typeof cExpr !== \"string\") {","sourceCodeStart":597,"sourceCodeEnd":633,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/scripting_api/app.js#L597-L633","documentation":"app.setInterval schedules a PDF-JavaScript expression for repeated evaluation after nMilliseconds. PDF.js requires the first argument to be the code string (or an object literal {cExpr, nMilliseconds}); if cExpr is not a string after coercion, a TypeError is thrown. This guards the sandbox from evaluating non-string input.","triggerScenarios":"Calling app.setInterval(someNumber, 1000), app.setInterval(null, 1000) after the object-form unwrap, or app.setInterval({cExpr: 42}) where cExpr is not a string. The check at src/scripting_api/app.js:615 fails typeof cExpr !== 'string'.","commonSituations":"Passing a function reference instead of a code string (common from JS authors used to window.setInterval); passing undefined when the expression is optional; object-form call missing cExpr.","solutions":["Pass the callback body as a string: app.setInterval('myFunc()', 1000).","If using object form, ensure {cExpr: 'myFunc()', nMilliseconds: 1000} has a string cExpr.","For a real JS function, inline its body as a string only if you must; otherwise use the host viewer's native scheduling."],"exampleFix":"// before\napp.setInterval(myFunc, 1000); // myFunc is a function\n// after\napp.setInterval('myFunc()', 1000); // Acrobat JS expects a code string","handlingStrategy":"type-guard","validationCode":"// Validate cExpr is a string before calling app.setInterval.\nfunction scheduleInterval(app, cExpr, nMilliseconds = 0) {\n  if (typeof cExpr !== 'string' || cExpr.length === 0) {\n    throw new TypeError('cExpr must be a non-empty string');\n  }\n  return app.setInterval(cExpr, nMilliseconds);\n}","typeGuard":"const isCodeString = (v) => typeof v === 'string' && v.trim().length > 0;","tryCatchPattern":"try { app.setInterval(maybeExpr, 1000); }\ncatch (e) {\n  if (!(e instanceof TypeError && /First argument of app\\.setInterval/.test(e.message))) throw e;\n  // fall back to no-op or host scheduler\n}","preventionTips":["Remember Acrobat JS app.setInterval takes a code string, not a function.","Validate input type before calling when values come from form fields.","Use the object form {cExpr, nMilliseconds} only with a string cExpr."],"tags":["scripting-api","type-validation","setinterval","acrobat-js"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}