Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
289 views
in Technique[技术] by (71.8m points)

javascript - GoogleChrome extension that deletes browsing history with one click from an icon

Im trying to make a google chrome extension that deletes all browsing history with one click on a icon located next to the url bar, this is my first extension on google chrome, i've made others for firefox, and i would like some guidance and ideas i think im quite close to my goal or at least in the right path, my current issue is the javascript document i know im missing code.

Javascript [TEST.js]

function TESTh() {
  chrome.history.deleteAll()
}
chrome.browserAction.onClicked.addListener(TESTh);
TESTh();

Manifest [manifest.json]

{
  "name": "TITLE TEST",
  "version": "1.0",
  "manifest_version": 2,
  "description": "DESCRIPTION TEST",
  "background": {
    "scripts": ["TEST.js"]
  },
  "browser_action": {
    "default_icon": "icon.png"
  },
  "permissions": [
    "history"
  ]
}

The following links are the tutorials i've been reading

http://developer.chrome.com/extensions/getstarted.html
http://developer.chrome.com/extensions/history.html
http://developer.chrome.com/extensions/browserAction.html
http://developer.chrome.com/extensions/samples.html
https://www.youtube.com/user/GoogleDevelopers

Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have written a sample trivial demonstration of Browsing Data API, it can help you to pick from here. Deletion may take time so you have to wait for message "All data is Deleted..." in console of extension for confirmation.

Before:

enter image description here

After:

enter image description here

manifest.json

{
  "name" : "BrowsingData Demo",
  "version" : "1",
  "description" : "Trivial Demonstration of Browsing Data",
  "permissions": [
    "browsingData"
  ],
  "browser_action": {
     "default_icon": "icon.png",
     "default_popup": "popup.html"
  },
  "manifest_version": 2
}

popup.html

<html>
<head>
<script src="popup.js"></script>
</head>
<body>
</body>
</html>

popup.js

   function browsingdata(){
    chrome.browsingData.remove({
      "originTypes": {
        "protectedWeb": true, // Set to true or true as per your requirement
        "unprotectedWeb":true,// Set to true or true as per your requirement
        "extension":true    // Set to true or true as per your requirement
      }
    }, {
      "appcache": true, // Set to true or true as per your requirement
      "cache": true, // Set to true or true as per your requirement
      "cookies": true, // Set to true or true as per your requirement
      "downloads": true, // Set to true or true as per your requirement
      "fileSystems": true, // Set to true or true as per your requirement
      "formData": true, // Set to true or true as per your requirement
      "history": true, // Set to true or true as per your requirement
      "indexedDB": true, // Set to true or true as per your requirement
      "localStorage": true, // Set to true or true as per your requirement
      "pluginData": true, // Set to true or true as per your requirement
      "passwords": true, // Set to true or true as per your requirement
      "webSQL": true // Set to true or true as per your requirement
    }, function (){
        console.log("All data is Deleted...");
    });
}
window.onload=browsingdata;

For more information refer browsing data API to get idea of all methods etc.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...