diff --git a/client/modules/IDE/components/Editor.jsx b/client/modules/IDE/components/Editor.jsx index 892028c4..cfedd841 100644 --- a/client/modules/IDE/components/Editor.jsx +++ b/client/modules/IDE/components/Editor.jsx @@ -188,7 +188,7 @@ class Editor extends React.Component { for (let i = 0; i < this._cm.lineCount(); i += 1) { this._cm.removeLineClass(i, 'background', 'line-runtime-error'); } - if (this.props.runtimeErrorWarningVisible && this._cm.getDoc().modeOption === 'javascript') { + if (this.props.runtimeErrorWarningVisible) { this.props.consoleEvents.forEach((consoleEvent) => { if (consoleEvent.method === 'error') { if (consoleEvent.data && @@ -197,7 +197,11 @@ class Editor extends React.Component { consoleEvent.data[0].indexOf(')') > -1) { const n = consoleEvent.data[0].replace(')', '').split(' '); const lineNumber = parseInt(n[n.length - 1], 10) - 1; - if (!Number.isNaN(lineNumber)) { + const { source } = consoleEvent; + const fileName = this.props.file.name; + const errorFromJavaScriptFile = (`${source}.js` === fileName); + const errorFromIndexHTML = ((source === fileName) && (fileName === 'index.html')); + if (!Number.isNaN(lineNumber) && (errorFromJavaScriptFile || errorFromIndexHTML)) { this._cm.addLineClass(lineNumber, 'background', 'line-runtime-error'); } } diff --git a/client/utils/consoleUtils.js b/client/utils/consoleUtils.js index 40ab1843..2f8ea1be 100644 --- a/client/utils/consoleUtils.js +++ b/client/utils/consoleUtils.js @@ -46,21 +46,36 @@ export const startTag = '@fs-'; export const getAllScriptOffsets = (htmlFile) => { const offs = []; - let found = true; + const hijackConsoleErrorsScriptLength = 36; + const embeddedJSStart = 'script crossorigin=""'; + let foundJSScript = true; + let foundEmbeddedJS = true; let lastInd = 0; let ind = 0; let endFilenameInd = 0; let filename = ''; let lineOffset = 0; - while (found) { + while (foundJSScript) { ind = htmlFile.indexOf(startTag, lastInd); if (ind === -1) { - found = false; + foundJSScript = false; } else { endFilenameInd = htmlFile.indexOf('.js', ind + startTag.length + 3); filename = htmlFile.substring(ind + startTag.length, endFilenameInd); - // the length of hijackConsoleErrorsScript is 36 lines - lineOffset = htmlFile.substring(0, ind).split('\n').length + 36; + lineOffset = htmlFile.substring(0, ind).split('\n').length + hijackConsoleErrorsScriptLength; + offs.push([lineOffset, filename]); + lastInd = ind + 1; + } + } + lastInd = 0; + while (foundEmbeddedJS) { + ind = htmlFile.indexOf(embeddedJSStart, lastInd); + if (ind === -1) { + foundEmbeddedJS = false; + } else { + filename = 'index.html'; + // not sure where the offset of 25 comes from + lineOffset = htmlFile.substring(0, ind).split('\n').length + 25; offs.push([lineOffset, filename]); lastInd = ind + 1; }