问题
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
回答1:
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:

After:

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.
来源:https://stackoverflow.com/questions/13557159/googlechrome-extension-that-deletes-browsing-history-with-one-click-from-an-icon