Currently, I am in the process of developing a unique chrome extension that randomly loads URLs from your bookmarks bar whenever a new tab is opened.
In my app.js file, you will find the following code snippet:
var bookmarksArray = [];
// This function traverses the bookmarks tree and saves URLs in the 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);
}
}
}
// Processes all user bookmarks
function createbookmarksArray(){
chrome.bookmarks.getTree(process_bookmark);
}
// Retrieves a random bookmark URL from the array and loads it
function getBookmark(){
window.location.href = bookmarksArray[Math.floor(Math.random()*bookmarksArray.length)];
}
// All necessary functions to be called upon Page Load
function onLoadFunctions(){
createbookmarksArray();
getBookmark();
}
// Function executed on page load
document.addEventListener("DOMContentLoaded", function(event) {
onLoadFunctions();
});
Additionally, my manifest.json requests permissions for newtab and bookmarks. The newtab is linked to index.html which then calls ap.js.
Upon running this extension, an error message "Your file was not found. It may have been moved or deleted.ERR_FILE_NOT_FOUND" appears.
Interestingly, running
window.location.href = bookmarksArray[Math.floor(Math.random()*bookmarksArray.length)];
in the console works flawlessly.
Could it be that I am incorrectly calling the functions?