Using Javascript function call with multilines in Firefox user.js file

I am encountering an issue with my user.js file that 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 perfectly fine. However, when the parameter is a multi-line string, it fails to work. Does anyone have any suggestions on how I can make this work as a multiline string while still maintaining readability?

Example that Works:


user_pref("browser.newtabpage.pinned", "[{\"url\":\"https://amazon.com/\",\"label\":\"amazon\",\"baseDomain\":\"amazon.com\"}...;

Example that Doesn't Work:

user_pref("browser.newtabpage.pinned",
`[
    {
        "url": "https://amazon.com/",
        "label": "amazon"...;
    },
    {
        "url": "https://app.ynab.com",
        "label": "ynab",
        "baseDomain": "app.ynab.com"
    }
]`);

Answer №1

It appears that the user.js file utilizes a limiter parser, which means that template strings may not function correctly in that context

Consider using basic strings with newline escapes instead, such as:

user_pref('browser.newtabpage.pinned',
'[                                       \
    {                                    \
        "url": "https://amazon.com/",    \
        "label": "amazon",               \
        "baseDomain": "amazon.com"       \
    },                                   \
    {                                    \
        "url": "https://app.ynab.com",   \
        "label": "ynab",                 \
        "baseDomain": "app.ynab.com"     \
    }                                    \
');

(please note that I have used single quotes to avoid the need for escaping characters)

Answer №2

Try using JSON.parse to transform it into an object (or write it as an object), and then use JSON.stringify to convert it back to the exact string format it requires.

user_pref(
   "browser.newtabpage.pinned",
   JSON.stringify(
       { blah: 999 }
   )
)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

getJSON takes precedence over other tasks

I am having a challenge retrieving data in JSON format from the server and displaying it dynamically in a table. The code runs without errors and successfully fetches the data, but for some reason, nothing appears in the table. I suspect there may be an ...

AngularJS filter date is returning a value of NaN-NaN-NaN

I'm facing an issue where the filter I developed is functioning properly on Chrome but not on Firefox. I am puzzled as to why this might be happening. myApp.filter('dateCustom', [ '$filter', function ($filter) { return funct ...

Preloading error alert message displayed during AJAX request

When I send an ajax request with a dropdown change, the loader div is shown using "before send". However, the issue is that the loader only displays for the first time, even though the ajax functionality works all the time. If you want to check this issue ...

What exactly does "Dirty" mean in the context of React.js?

As I delve into learning React.js, a term that frequently arises is "Dirty" - used in the context of dirty checker/checking, dirty data, and dirty model. I attempted to make sense of this concept by reading this question, but I still struggle to grasp wha ...

Assistance with Redirecting Responses in Next.js API Routes

I'm currently working on implementing a login functionality in Next.js. I have made significant progress but I am facing an issue with redirecting to the homepage after a successful login. My setup involves using Next.js with Sanity as the headless CM ...

What is the proper method for initiating an ajax request from an EmberJs component?

Curious to learn the correct method of performing an ajax call from an Ember component. Let's say, for instance: I am looking to develop a reusable component that allows for employee search based on their Id. Once the server responds, I aim to update ...

loading external files with processing.js

Splitting my processing.js code into multiple files is something I want to do, but I'm a bit unsure on how to proceed. I attempted using the following code: <script type="application/processing" src="main.pjs"> in order to load my processing.j ...

Generating a JSON form to enable users to search for specific dates within a given range by utilizing the "datetime" data type

Currently, I am in the process of developing a form that can search for specific data within a JSON's datetime value. The objective is to retrieve information from the JSON that falls between the first and last dates entered by the user. However, desp ...

"Displaying the state value retrieved from a custom hook is not working as expected

Creating a custom hook, Custom.js: import React, {useState, useEffect} from 'react'; import Clarifai from 'clarifai'; const app = new Clarifai.App({ apiKey: 'XXXXXXXXXXXXXX' }) const CustomHook = () => { const [i ...

How to dynamically load a file based on the chosen option value in React

Two select textboxes on my page are named Choose City and Choose District. I also have some files related to cities and districts: // cities.js const cities = { "01": { "name": "City 1", "code": "01" }, ...

Retrieve JavaScript functions as JSON or text in AngularJS and execute them

Currently, I am working on developing an AngularJS application and have come across a particular challenge that needs to be addressed: After making a web service call, I receive JavaScript code that looks like this: { "script":"function foo(a, b) { c = ...

<fieldset> triggering onChange event in React form

I am facing an issue with my React component where multiple onChange functions are not getting fired. After some debugging, I realized that the problem lies with the fieldset element within the form. Removing the fieldset allows all onChange functions to w ...

The `diff` command is causing issues in `execSync`, resulting in errors when the files do not

Why am I getting an error with the diff command when my files don't match? let {stdout,stderr,err} = execSync(`diff output.txt answer.txt`, { cwd: "/home", encoding: 'utf8' }); if (err) { console.log(err); } console.log(stdout); The ...

Is there a way to streamline this generator without using recursion?

I need to develop a unique value generator that produces values within a specified range. The criteria are: all generated values must be distinct the order of values remains consistent upon each run of the generator each value should be significantly diff ...

displaying empty page using react router

I can't seem to figure out why my render is resulting in a blank page. I've searched through similar questions for a solution but haven't had any luck so far. Any help would be greatly appreciated! Here's my code: App.js import log ...

What are the best ways to customize exported and slotted components in Svelte?

Is there a similarity between Svelte slots and vanilla-js/dom functionality (I'm having trouble with it). In html/js, I can achieve the following: <style> body {color: red;} /* style exposed part from outside */ my-element::par ...

Navigating to a particular value in Vue: A step-by-step guide

In my Vue application, I have a basic table structure: <tbody> <tr v-for="(item, index) in items"> <td> ... </td> </tr> </tbody> The items are dynamically added using the unsh ...

The element's height appears to be fluctuating unexpectedly when I attempt to adjust it using percentage values within a narrow range

I'm utilizing React and Bootstrap in this project. Here's an overview of my code: I have an element with height set to 0, in rem. My goal is to make the height of this element increase as I scroll down the page, creating the illusion that it is ...

What is the best way to parse a JSON file on an iPhone device?

Recently, I have started learning about programming for iPhones and I need some assistance with parsing JSON strings. Specifically, I am working on JSON parsing in my application. Below is the JSON data that I am dealing with: The structure of JSON looks l ...

Explore a JSON array within another JSON array

Here is a JSON format that I have: { "Project [id=1, dateDebut=2017-01-13, dateFin=2017-01-18, description=qsd, sponsor=qsd ]" : [ {"id":1,"title":"qsd ","description":"qsdqsd","dateFin":"2017-01-26"}, {"id":2,"title":"sss ","descriptio ...