The Chrome file storage system saves information in files

My challenge is to save data obtained from the Chrome geolocation API into a text file using the Chrome fileSystem API. However, despite successfully creating a file, it remains empty after the process. To simplify, I attempted to add the string '1234567890' to the file. In the provided code, I included console.log statements to identify the lines of code that are not executing, and it appears that the code is not running from writableFileEntry.createWriter() onwards.

chrome.fileSystem.chooseEntry({type: 'saveFile'}, function(writableFileEntry) {
   console.log('writableFileEntry - here');
    writableFileEntry.createWriter(function(writer) {
      console.log('After writableFileEntry - here');
      writer.onerror = errorHandler;
      writer.onwriteend = function(e) {
        console.log('write complete');
      };
       console.log('before Blob - here');
      writer.write(new Blob(['1234567890'], {type: 'text/plain'}));
    }, errorHandler);
});

The contents of the manifest.json file are as follows:

"permissions": ["location","geolocation", "storage", "unlimitedStorage", "fileSystem", "syncFileSystem", {"fileSystem": ["write"]}
          ],
  "app": {
    "background": {
      "scripts": ["background.js"]
        }
      },
  "sockets": {
        "tcp": {
            "connect": "localhost:80"
        },
        "udp": {
             "send": "localhost:80"
        }
      }

Any assistance or recommendations would be greatly appreciated! Thank you, Ofer

Answer №1

Recently, I encountered a similar issue after implementing some code from the Google documentation. The code mentioned a function called errorHandler that was not defined. To resolve this problem, simply add a new function called errorHandler() to your code.

Here is an example of how to incorporate the errorHandler() function:

chrome.fileSystem.chooseEntry({type: 'saveFile'}, function(writableFileEntry) {

        function errorHandler(){
            console.log('error');
        };

        writableFileEntry.createWriter(function(writer) {
          writer.onerror = errorHandler;
          writer.onwriteend = function(e) {
            console.log('write complete');
          };
          writer.write(new Blob(['1234567890'], {type: 'text/plain'}));
        }, errorHandler);

    });

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

Encountering a Type Error while attempting to display items from an array

Encountering an issue while attempting to load quiz questions from a db.json server. The error message reads: "TypeError: this.state.questions[this.state.currentQuestion] is undefined". In order to provide more context, here's a link to a sandbox of m ...

The input field malfunctioned after the clear button was pressed

Hi there, I have a question. Every time I try to click on the clear button, it keeps giving me an error message and I'm not sure what the issue is. Also, I can't type in the field anymore after clicking it. methods: { add () { this.ta ...

Coding in PHP, JavaScript, and HTML allows builders

I am facing some difficulties in locating my specific question, so I will describe it here. Currently, I am working with an oracle database and integrating it into an HTML website using javascript and php. I have successfully displayed the php file, but th ...

What's the Deal with Blank Square Brackets in JavaScript?

While browsing through , I stumbled upon this code snippet: useEffect(() => { const interval = setInterval(() => { console.log('This will run every second!'); }, 1000); return () => clearInterval(interval); }, []); I am intri ...

Error encountered when attempting to upload image on Twitter: missing media parameter

According to the latest Twitter media upload API documentation, it is recommended to first utilize either POST multipart/form-data or base64 encoded files when interacting with . However, encountering an error with code 38 stating "media parameter is mi ...

Generating step definitions files automatically in cucumber javascript - How is it done?

Is there a way to automatically create step definition files from feature files? I came across a solution for .Net - the plugin called specflow for Visual Studio (check out the "Generating Step Definitions" section here). Is there something similar avail ...

What is the designated action or code in question?

let specialty = ''; function isVegetarian() { }; function isLowSodium() { }; export { specialty, isVegetarian }; export { specialty, isVegetarian }; The explanation from the editor was as follows: When exporting objects, it is done by the ...

Recreating the rotation of an object within a rotated parent using Three.js

After constructing my 3D globe and placing it within a parent bounding box / pivot, the code looked like this: var globe = new THREE.Group(); if (earthmesh) {globe.add(earthmesh);}; if (linesmesh) {globe.add(linesmesh);}; if (cloudmesh) {globe.add(cloudmes ...

The dropdown feature appears to be malfunctioning in my ReactJS Bootstrap project

I'm currently working with reactJS and Bootstrap. I am attempting to display a user image with a dropdown menu, where the dropdown will open when the user clicks on it. Unfortunately, my dropdown is not functioning as expected. Below is the code sni ...

Having an excess of 32 individual byte values

My current project involves developing a permission system using bitwise operators. A question came up regarding the limitation of having only 32 permissions in place: enum permissions { none = 0, Founder = 1 << 0, SeeAdmins = 1 << ...

Leverage JavaScript to retrieve the number of active Ajax requests in JSF

When running Selenium tests using JS, I want to ensure that there are no active Ajax requests. While I can successfully extract the amount of active Ajax requests for jQuery and PrimeFaces, I am facing some issues with JSF. String jsPF = "return PrimeFace ...

AngularJS fails to prioritize the following element

Here is my HTML code: <div ng-app="app"> <form> <div class="form-group"> <label >Username</label> <input focus type="text" class="form-control" id="loginUserName" ng-model="userForm.crn" required/> ...

How can jQuery retrieve a string from a URL?

If I have a URL like http://www.mysite.com/index.php?=332, can jQuery be used to extract the string after ?=? I've searched on Google but only found information about Ajax and URL variables that hasn't been helpful. if (url.indexOf("?=") > 0) ...

The input given to Material UI autocomplete is incorrect, even though the getOptionSelect parameter already exists

I'm currently working on creating my own version of the Google Places autocomplete found in the Material UI documentation. While I have successfully implemented the autocomplete feature and am able to update my component's state with the result, ...

How come eslint is unable to detect all files within a directory, yet it can detect a single file?

Here is the organization of my files and directories. https://i.stack.imgur.com/YWNw3.png I am looking to set up some eslint rules for my code detection. In my .eslintrc file, I have included these configuration settings. { "extends": "airbnb", "ru ...

Is handlebars.js giving you trouble all of a sudden?

My handlebars.js template was working perfectly for a week, but suddenly stopped. I'm puzzled by this issue and would appreciate any insights on why it might have stopped functioning. Here is the template: <script id="banners-template" type=" ...

Create directories in a nested structure using a multi-level JSON object with async.js

DEFINITION NewMethod#generateDirectoriesFromJSON (data, cb); data: JSON object. cb: Callback function. Parameters: err (Error), directoriesCreated (Boolean, true if at least one directory has been created). Assuming that the NewMethod class includes a ...

Passing an array through ajax from PHP to JavaScript using a properly formatted JSON structure

I began with an array generated by PHP and retrieved via ajax, which had the following structure: Array ( [0] => {id:"12",from:"09:00:00",to:"15:00:00"} [1] => {id:"13",from:"08:00:00",to:"10:00:00"} [2] => {id:"12",from:"15:00:00",to ...

Retrieve the chosen item to automatically fill in the input fields using Ionic 2 and Angular

My goal is to create a dropdown menu populated with a list of items, and when a product is selected, its price should automatically appear in the quantity field. <ion-item> <ion-label>Item</ion-label> <ion-select (ionChange)="getP ...

Escape sequences do not seem to be functioning properly when using innerHTML

I am facing an issue where a string containing HTML escape characters (such as < and >) needs to be rendered inside a div using innerHTML. The intention is for the escaped characters to appear as text rather than as actual HTML, but they still render ...