I am building a chrome extension to load a random URL from your bookmarks bar when you open a new tab.
My app.js has the following code:
var bookmarksArray = [];
// Function to traverse the bookmarks tree and save URLs in bookmarksArray
function process_bookmark(bookmarks) {
for (var i =0; i < bookmarks.length; i++) {
var bookmark = bookmarks[i];
if (bookmark.url) {
bookmarksArray.push(bookmark.url);
}
if (bookmark.children) {
process_bookmark(bookmark.children);
}
}
}
// Process all bookmarks of user
function createbookmarksArray(){
chrome.bookmarks.getTree(process_bookmark);
}
// Get random bookmark URL from array and load it
function getBookmark(){
window.location.href = bookmarksArray[Math.floor(Math.random()*bookmarksArray.length)];
}
// All functions to be called on Page Load
function onLoadFunctions(){
createbookmarksArray();
getBookmark();
}
// Function to be run on page load
document.addEventListener("DOMContentLoaded", function(event) {
onLoadFunctions();
});
Also my manifest.json asks for the newtab and bookmarks permissions. newtab is set to index.html which calls ap.js
When I run this extension, I get a "Your file was not found. It may have been moved or deleted.ERR_FILE_NOT_FOUND" error.
When I run window.location.href =bookmarksArray[Math.floor(Math.random()*bookmarksArray.length)];
in the console, it works perfectly fine.
Am I calling the functions wrong?