Hi,
I am writing a simple extension to do the following:
When I open a web page, and then press a hotkey (Ctrl + Space), the page should scroll to a certain vertical position (500px).
Here is the code I currently have:
manifest.json
{
"name": "Scroll",
"description" : "Scroll.",
"version": "1.0",
"manifest_version": 2,
"background": {
"scripts": ["script.js"],
"persistent": false
},
"commands": {
"scroll": {
"suggested_key": {
"default": "Ctrl+Space"
},
"description": "Scroll"
}
}
}
script.js
chrome.commands.onCommand.addListener(function (command) {
if (command == "scroll") {
alert("Test");
}
});
When I test the above, it works.
chrome.commands.onCommand.addListener(function (command) {
if (command == "scroll") {
window.scrollTo(0, 500);
}
});
When I test the above, it doesn’t work.
Any ideas why alert() is working but window.scrollTo() is not working?
Thanks.