This extension is supposed to allow users to select a site that they wish to search quickly using a keyword in the omnibox.
Here is my options.html
. This file should give users the ability to pick a website preference and save it to chrome.storage.sync
. I set a default to search google:
<!DOCTYPE html>
<html>
<head><title>Search Options</title></head>
<body>
Search:
<select id="url">
<option value="https://google.com/search?q=">Site1</option>
<option value="url#2.com?search=">
Site2
</option>
</select>
<div id="status"></div>
<button id="save">Save</button>
<script src="options.js"></script>
</body>
</html>
my options.js. This file is supposed to contain functions that save and restore options:
// Saves options to chrome.storage
function save_options() {
var url = document.getElementById('url').value;
chrome.storage.sync.set({prefSite: url}, function() {
// Update status to let user know options were saved.
var status = document.getElementById('status');
status.textContent = 'Options saved.';
setTimeout(function() {
status.textContent = '';
}, 750);
});
}
// Restores select box and checkbox state using the preferences
// stored in chrome.storage.
function restore_options() {
// Use default site: Google
chrome.storage.sync.get({prefSite: 'https://google.com/search?q='}, function(items) {
document.getElementById('url').value = items.prefSite;
});
}
document.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('save').addEventListener('click',
save_options);
and my background.js
. In this file I allow the user to search their selected webpage from the omnibox using a keyword:
function resetDefaultSuggestion() {
chrome.omnibox.setDefaultSuggestion({
description: 'Search for: %s'
});
}
resetDefaultSuggestion();
chrome.omnibox.onInputCancelled.addListener(function() {
resetDefaultSuggestion();
});
chrome.omnibox.onInputEntered.addListener(function(text) {
var prefSite = chrome.storage.sync.get("prefSite", function (obj) {
console.log(obj);
});
var SearchURL = prefSite + text;
chrome.tabs.create({url: SearchURL });
});
When I try to search I see this page. Any ideas why this isn't working?