I have a user.js file which sets user_prefs()
for the new tab page in firefox. When I have the function call on a single line with escaped quotes, it works fine, but when the parameter is a multi-line string it doesn’t work. Any ideas how I can have this work as a multiline string (for readability)?
Works:
user_pref("browser.newtabpage.pinned", "[{"url":"https://amazon.com/","label":"amazon","baseDomain":"amazon.com"},{"url":"https://mail.google.com/mail/u/0/#inbox","label":"mail"},{"url":"https://www.facebook.com/","label":"facebook","baseDomain":"facebook.com"},{"url":"https://twitter.com/","label":"twitter","baseDomain":"twitter.com"},{"url":"https://www.instagram.com/","label":"instagram","baseDomain":"instagram.com"},{"url":"https://www.reddit.com/","label":"reddit","baseDomain":"reddit.com"},{"url":"https://www.youtube.com/","label":"youtube","baseDomain":"youtube.com"},{"url":"https://keep.google.com/","label":"keep.google","baseDomain":"keep.google.com"},{"url":"https://app.plex.tv/desktop/#!/","label":"app.plex","baseDomain":"app.plex.tv"},{"url":"https://www.phoronix.com/scan.php?page=home","baseDomain":"phoronix.com"},{"url":"http://192.168.50.2","label":"nas","baseDomain":"192.168.50.2"},{"url":"http://192.168.50.2:8080","label":"app","baseDomain":"192.168.50.2"},{"url":"https://www.protondb.com/","label":"proton","baseDomain":"protondb.com"}]");
Doesn’t work:
user_pref("browser.newtabpage.pinned",
`[
{
"url": "https://amazon.com/",
"label": "amazon",
"baseDomain": "amazon.com"
},
{
"url": "https://mail.google.com/mail/u/0/#inbox",
"label": "mail"
},
{
"url": "https://www.facebook.com/",
"label": "facebook",
"baseDomain": "facebook.com"
},
{
"url": "https://twitter.com/",
"label": "twitter",
"baseDomain": "twitter.com"
},
{
"url": "https://www.instagram.com/",
"label": "instagram",
"baseDomain": "instagram.com"
},
{
"url": "https://www.reddit.com/",
"label": "reddit",
"baseDomain": "reddit.com"
},
{
"url": "https://www.youtube.com/",
"label": "youtube",
"baseDomain": "youtube.com"
},
{
"url": "https://keep.google.com/",
"label": "keep.google",
"baseDomain": "keep.google.com"
},
{
"url": "https://app.plex.tv/desktop/#!/",
"label": "app.plex",
"baseDomain": "app.plex.tv"
},
{
"url": "https://www.phoronix.com/scan.php?page=home",
"baseDomain": "phoronix.com"
},
{
"url": "http://192.168.50.2",
"label": "nas",
"baseDomain": "192.168.50.2"
},
{
"url": "http://192.168.50.2:8080",
"label": "app",
"baseDomain": "192.168.50.2"
},
{
"url": "https://www.protondb.com/",
"label": "proton",
"baseDomain": "protondb.com"
},
{
"url": "http://lichess.org",
"label": "lichess",
"baseDomain": "lichess.org"
},
{
"url": "https://app.ynab.com",
"label": "ynab",
"baseDomain": "app.ynab.com"
}
]`);
2
Answers
Use
JSON.parse
to convert in to object (or even write is as object) and thenJSON.stringify
to convert it back to exactly the string it expectsIt seems that the user.js uses a limiter parser, so I guess template string just don’t work there
Try using basic strings with newline escapes, like
(note that I use ‘ strings to avoid " escapes)