Is it possible to write to the local file from within the chrome extension?

Asked 1 years ago, Updated 1 years ago, 107 views

I don't think it's safe to rewrite the local file just by accessing the site with a normal javascript, but I think it's possible to do it if it's intentionally installed with an extension.

What I want to do is to keep the response of a particular site in storage with the chrome extension, and the response content can now be retrieved as a javascript string within the extension

I think it's possible to set up a log server locally and send it there to save it on the server, but if you build a separate server, it will be complicated, so if you can save it within the chrome extension, you only need a browser, so I asked you.

manifest.json

"devtools_page":"devtools.html"


from devtool.js in devtool page devtool.html in chrome.devtools.panels.create
I would like to create a panel.html in and write files in panel.js in that panel.html

If you can't do it, just answer that you can't do it
If so, I will quietly set up a log server, so it will be helpful

"When I searched ""Write javascript file"", I got a few messages, but

"

Tried FileSystemAPI with Chrome extensions

This is the following error

Uncaught ReferenceError: WebKitBlobBuilder is not defined

Write Chrome extensions to the local file system

This will also result in the following error

window.requestFileSystem is not a function

Try the Native File System API

The following error occurs

Uncaught(inpromise) DOMException: Failed to execute 'showSaveFilePicker' on 'Window': Cross origin subframes arena't allowed to show a file picker.

chrome-extension google-chrome-devtools

2022-09-29 22:15

1 Answers

The API specification seems to have changed from the article provided, but I even tried creating a new file with the File System Access API

This article was easy to understand because there were a lot of samples.
https://web.dev/file-system-access/

The specification page is also for your reference
https://wicg.github.io/file-system-access/

// Call test() when writing
async function test(){
    consthandle=wait getNewFileHandle()
    wait writeFile(handle, "hello")
}

async function getNewFileHandle(){
    constoptions={
      types: [
        {
          description: 'Text Files',
          accept: {
            'text/plain': ['.txt',
          },
        },
      ],
    };
    command=wait window.showSaveFilePicker(options);
    return handle;
}

async function writeFile(fileHandle, contents) {
    const writable = wait fileHandle.createWritable();
    wait writable.write(contents);
    wait writable.close();
}


2022-09-29 22:15

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.