From 1125b70500248b57fa851761c44bdb6437a45668 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20Norman=20Hauk=C3=A5s?= Date: Sun, 24 Jan 2016 16:12:11 +0100 Subject: [PATCH] Added better handling of failed tag deserializations. It will no longer block plugin loading. --- .gitignore | 3 ++- src/services/webpage.service.ts | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index ba30c8a..76bfcbd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules dist tmp -*.zip \ No newline at end of file +*.zip +.idea/ \ No newline at end of file diff --git a/src/services/webpage.service.ts b/src/services/webpage.service.ts index 8e08ec1..8a001dd 100644 --- a/src/services/webpage.service.ts +++ b/src/services/webpage.service.ts @@ -94,14 +94,15 @@ module tagIt { //first deselect before we go to work this.iframeDocument.getSelection().removeAllRanges(); - //deserialize ranges - _.map(tagsToLoad, (tagToLoad) => { + //deserialize ranges, remove the ones that fail. + tagsToLoad = _.filter(tagsToLoad, (tagToLoad) => { try { tagToLoad.deserializedRange = rangy.deserializeRange( tagToLoad.serializedSelectionRange, this.iframeDocument.documentElement, this.iframeWindow ); + return true; } catch (e) { var errorMsg = `Error in rangy.js: Was not able to deserialize range. In other words: The page might have changed. Is not able @@ -109,8 +110,9 @@ module tagIt { this.$log.debug(errorMsg); this.$log.debug("Couldn't load: " + tagToLoad.sense.word); this.$log.debug(e); + return false; } - }); + }) this.$log.debug('finished deserializing tags');