From 4bf654bb5f9689fd9a1ea03d9e84bfffbb124ce7 Mon Sep 17 00:00:00 2001 From: SleekPanther Date: Tue, 10 Jul 2018 17:30:21 -0400 Subject: [PATCH] Error handling to make sure it's a valid VIDEO url --- background.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/background.js b/background.js index be0f811..0ee37ab 100644 --- a/background.js +++ b/background.js @@ -30,7 +30,11 @@ function appendToUrl(){ chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, tabs=>{ let currentTab = tabs[0] let oldURL = currentTab.url - let videoId = oldURL.match(regexMatchVideoId)[1] //get video id + let regexMatch = oldURL.match(regexMatchVideoId) + if(!regexMatch){ //not a valid youtube video URL (prevents keyboard shotcut override) + return + } + let videoId = regexMatch[1] //get video id let newUrl = YOUTUBE_VIDEO_URL_START + videoId + MAGIC_URL_POSTFIX chrome.tabs.update(currentTab.id, {url: newUrl}) //update tab/reloads page with new location })