在 Chrome 扩展程序中写入本地文件系统 [英] Writing to local file system in Chrome extension

查看:73
本文介绍了在 Chrome 扩展程序中写入本地文件系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

chrome.tabs.onUpdated.addListener(checkForValidUrl);
function checkForValidUrl(tabId, changeInfo, tab) {
    if (tab.url.indexOf('https') > -1) {
        var tabURL = tab.url;
        console.log("
<TimeStamp>" + getTimestamp() + "</TimeStamp><Browser>Chrome</Browser><URL>" + tabURL + "</URL>
");
        window.requestFileSystem(window.PERSISTENT, 5 * 1024 * 1024, initFs);

        function initFs(fs) {
            fs.root.getFile
            ('log.txt', { create: true, exclusive: true }, function (fileEntry) {
                fileEntry.isFile = true;
                fileEntry.name = 'log.txt';
                fileEntry.fullPath = '/log.txt';
                fileEntry.createWriter(function (fileWriter) {
                    fileWriter.seek(fileWriter.length);
                    var bb = new BlobBuilder();
                    bb.append("
<TimeStamp>" + getTimestamp() + "</TimeStamp><Browser>Chrome</Browser><URL>" + tabURL + "</URL>
");
                    fileWriter.write(bb.getBlob('text/plain'));
                });
            });
        }
    }
}

推荐答案

基于此:

在撰写本文时,谷歌浏览器 9+ 有唯一的工作文件系统 API 的实现.由于专用浏览器 UI 没有还存在用于文件/配额管理,API 不运行就不能使用铬与--unlimited-quota-for-files 标志(注意:如果您正在构建应用程序或Chrome 网上应用店的扩展程序,无限存储清单文件许可就足够了).

At the time of writing this article, Google Chrome 9+ has the only working implementation of the FileSystem API. Since a dedicated browser UI does not yet exist for file/quota management, the API cannot be used without running Chrome with the --unlimited-quota-for-files flag (Note: if you're building an app or extension for the Chrome Web Store, the unlimitedStorage manifest file permission will suffice).

位于 http://www.html5rocks.com/tutorials/file/filesystem/#toc-支持

我假设您使用的是 Chrome 并且您没有设置 --unlimited-quota-for-files 标志

I assume you are using Chrome and that you have not set the --unlimited-quota-for-files flag

这篇关于在 Chrome 扩展程序中写入本地文件系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆