Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
31
rated 0 times [  33] [ 2]  / answers: 1 / hits: 20688  / 6 Years ago, mon, july 23, 2018, 12:00:00

I am trying create a bookmarks (on this case in chrome)



API/bookmarks/create



my code is :





	function onCreated(node) {
console.log(node);
}

var createBookmark = browser.bookmarks.create({
title: bookmarks.create() on MDN,
url: https://developer.mozilla.org/Add-ons/WebExtensions/API/bookmarks/create
});

createBookmark.then(onCreated);

<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>

<p>text example</p>
</body>
</html>





I got this error when I run the code in chrome:



Uncaught ReferenceError: browser is not defined


I run other code this :





function onFulfilled(bookmarkItems) {
if (bookmarkItems.length) {
console.log(active tab is bookmarked);
} else {
console.log(active tab is not bookmarked);
}
}

function onRejected(error) {
console.log(`An error: ${error}`);
}

function checkActiveTab(tab) {
var searching = browser.bookmarks.search({url: tab.url});
searching.then(onFulfilled, onRejected);
}

browser.browserAction.onClicked.addListener(checkActiveTab);





from :here I got the same error.



Update question :



my manifest.json in this moment:





 {
name: add site random,
version: 1.0,
description: this is my first extension in production,
manifest_version: 2
}





any idea because I have this error I am trying create a folder and add a site in my bookmarks from the code?


More From » bookmarks

 Answers
4

From your recent edit and by looking at your manifest.json it looks like you are missing few permissions field,



Hence update your manifest.json like this, (then package a new extension afresh)



{
name: add site random,
version: 1.0,
description: this is my first extension in production,
manifest_version: 2,
background: {
scripts: [YOUR_BACKGROUND_SCRIPT_NAME.js]
},
permissions: [
notifications,
activeTab
]
}


Hope this helps!


[#53914] Wednesday, July 18, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kevonmoisesf

Total Points: 693
Total Questions: 101
Total Answers: 128

Location: Reunion
Member since Mon, Dec 28, 2020
3 Years ago
kevonmoisesf questions
Sat, Jan 23, 21, 00:00, 3 Years ago
Tue, Feb 18, 20, 00:00, 4 Years ago
Wed, Jun 12, 19, 00:00, 5 Years ago
;