0

I discover the development of webextensions for firefox To start, I would like to access my bookmarks. Step by step I build my Webextensions , using (about:debugging/ "load temporary add-on")

I try, for testing, to access to Recent bookmarks .

I found the function getRecent() , With beautiful doc : https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/bookmarks/getRecent

I try to run the example on the page. but it does not work. After the content of my extension and the resultat

manifest.json

{
"manifest_version": 2,
"name": "Borderify",
"version": "1.0",
"description": "Adds a solid red border to all webpages matching mozilla.org.",
"icons": {
    "48": "icons/border-48.png"
},    
"content_scripts": [
    {
      "matches": ["*://*.mozilla.org/*"],
      "js": ["borderify.js"]
    }
],

"permissions": [ "bookmarks","tabs"]
}

borderify.js

document.body.style.border = "5px solid red";
console.log("Start : I'm display when I'an on mozilla.org");

function onFulfilled(bookmarks) {
    for (bookmark of bookmarks) {
    console.log(bookmark.url);
    }
}

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

var gettingRecent = browser.bookmarks.getRecent(1);
gettingRecent.then(onFulfilled, onRejected);

console.log("END : Not Display");

The result: enter image description here

I know it's a stupid extension but I do not understand why it does not work Thank's for your helping

Bob's Jellyfish
  • 353
  • 1
  • 3
  • 8
  • https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Content_scripts – Daniel Herr Jan 28 '17 at 18:56
  • What *exactly* is shown in the [various appropriate consoles for your extension](http://stackoverflow.com/a/38920982/3773011) when you load and execute your extension? – Makyen Jan 28 '17 at 21:14
  • I would suggest that you read the [Anatomy of a WebExtension](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Anatomy_of_a_WebExtension) page (and perhaps work through reading the pages linked from there). It has overall architecture information which should help your understanding of how things are generally organized/done. – Makyen Jan 28 '17 at 21:18
  • 1
    Your *borderify.js* script is running as a content script. [Content scripts don't have access to the `bookmarks` API.](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Content_scripts#WebExtension_APIs) You will need to use a background script (see the proposed duplicate question, or the above link). – Makyen Jan 28 '17 at 21:38

0 Answers0