开发者

Chrome extension - just to save current page into local html file

开发者 https://www.devze.com 2023-04-08 16:42 出处:网络
I am new to both Chrome extension development and website techniques (mainly JS). Trying to learn by myself, I wanted开发者_如何学Python to create a Chrome extension that can save the current page, s

I am new to both Chrome extension development and website techniques (mainly JS).

Trying to learn by myself, I wanted开发者_如何学Python to create a Chrome extension that can save the current page, say, to desktop. I know this simply can be done by "Ctrl+S", but I want to implement the same thing as a Chrome extension.

If possible, I want to create an extension that first create a popup menu, in which the top row will be the button to save page.

I tried to figure it out by myself, however, I got the code below, which is not working. Could you please give me some hints on how to proceed?

manifest.json

{
  "name": "Extract",
  "version": "2.0",
  "description": "The first extension that I made.",
  "browser_action": {
    "default_icon": "icon.png",
    "popup": "popup.html"
  },
  "permissions": [
    "tabs"
  ]
}

popup.html

<style>
body {
  min-width:357px;
  overflow-x:hidden;
}

img {
  margin:5px;
  border:2px solid black;
  vertical-align:middle;
  width:75px;
  height:75px;
}
</style>

<script>
function saveAsMe (filename)
{
    document.execCommand('SaveAs',null,filename)
}
</script>

Thanks in advance!


You cannot write files to disk using HTML5 or extensions unless you go native with NPAPI. There are FileSystem APIs that you can use to store it in the Chrome file system. AFAIK, last time I used it it created some GGUID file which you cannot change.

For more information regarding this, visit the HTML5 Tutorial regarding Exploring the FileSystem APIs

0

精彩评论

暂无评论...
验证码 换一张
取 消