-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Hi,
This evening, the Savetube script (2022.07.11) stopped working on Youtube for Firefox
Digging in the console, we get:
Uncaught (in promise) SyntaxError: unterminated regular expression literal
ytGetUnscrambleParamFunc moz-extension://437a936d-5257-43bf-a2f7-372a6e0a7b5b/userscripts/SaveTube.user.js?id=5095000f-66d1-4199-ade0-8aace8f6b18a:799
SaveTube moz-extension://437a936d-5257-43bf-a2f7-372a6e0a7b5b/userscripts/SaveTube.user.js?id=5095000f-66d1-4199-ade0-8aace8f6b18a:919
window["__f__ljqiosax.rql"]/</< moz-extension://437a936d-5257-43bf-a2f7-372a6e0a7b5b/userscripts/SaveTube.user.js?id=5095000f-66d1-4199-ade0-8aace8f6b18a:1308
window["__f__ljqiosax.rql"]/< moz-extension://437a936d-5257-43bf-a2f7-372a6e0a7b5b/userscripts/SaveTube.user.js?id=5095000f-66d1-4199-ade0-8aace8f6b18a:1322
St https://www.youtube.com/watch?v=ZU74ATbAhns:9
window["__f__ljqiosax.rql"]/< moz-extension://437a936d-5257-43bf-a2f7-372a6e0a7b5b/userscripts/SaveTube.user.js?id=5095000f-66d1-4199-ade0-8aace8f6b18a:1
"__f__ljqiosax.rql" moz-extension://437a936d-5257-43bf-a2f7-372a6e0a7b5b/userscripts/SaveTube.user.js?id=5095000f-66d1-4199-ade0-8aace8f6b18a:1
St https://www.youtube.com/watch?v=ZU74ATbAhns:9
s https://www.youtube.com/watch?v=ZU74ATbAhns:72
<anonymous> https://www.youtube.com/watch?v=ZU74ATbAhns:75
g https://www.youtube.com/watch?v=ZU74ATbAhns:69
The erroneous line at 799 is
ytMainFuncBody = 'try {' + ytMainFuncBody + '} catch(e) {return null}';
Adding some console logs, it seems the body of the parsed ytMainFuncBody function is:
var b=a.split(""),c=[-265090265,751968325,-1951798130,160288705,function(d,e,f,h,l,m,n,p){return e(f,h,l,m,n,p)},
1941204574,/()\/"()(;)[;,'
which looks indeed truncated
From the original script https://www.youtube.com/s/player/1dda5629/player_ias.vflset/fr_FR/base.js we see a regex /()\/"()(;)[;,'};]();/ which holds a dandling "}", that probably breaks the parser
As a quick and dirty fix, I made the "parseMyContent" function as below:
function parseMyContent(content, pattern) {
var parse, response;
content = content.replace(/(\r\n|\n|\r)/gm, '');
content = content.replace("/()\\/\"()(;)[;,'};]();/","/####/"); // Manual dirty patch
parse = content.match(pattern);
if (parse) {
response = (/g$/.test(pattern)) ? parse : parse[1];
response = response.replace("/####/", "/()\\/\"()(;)[;,'};]();/"); // Manual dirty patch
}
return response;
}
By replacing the regex with dandling "}" before running the parsing Regex of line 797 ( ytMainFuncBody = getMyContent(ytScriptUrl, new RegExp('(?:^|;)' + ytMainFuncName.replace(/\$/, '\\$') + '\\s*=\\s*function\\s*' + '\\s*\\(\\w+\\)\\s*\\{(.*?)\\};')); ) I get a properly parsed youtube script and SaveTube works again
I'm not opening a pull request here, because this is clearly not a nice "fix", but I wanted to share my root cause analysis of this issue so you may find a proper fix quicker and easier :)
(Note: since I edited this parseMyContent, i'm not 100% of my line numbers in this issue)