Google Chrome extension's content script not working on few pages -
i developing simple chrome extension, when password-input box focused. i'm using following content script achieve same (code simplified asking question). code not work on pages https://accounts.google.com/ works pages https://www.linkedin.com/. because of javascript/jquery conflicts? or other reason? please help. tried using noconflict api, didn't help.
content script:
var inputs = document.getelementsbytagname('input'); function foo() { (var = 0; < inputs.length; i++) { if (inputs[i].type.tolowercase() == 'password') inputs[i].addeventlistener("focus", bar); } } function bar() { alert(1); } foo();
above script finds input elements of type passwords, not add event listener.
manifest:
{ "manifest_version": 2, "name": "myextension", "version": "1.0", "options_page": "options.html", "browser_action": { "default_icon": "img/abcd.png", "default_title": "myextension", "default_popup": "popup.html" },"icons": { "16": "img/abcd16.png", "48": "img/abcd48.png", "128": "img/abcd128.png" },"description":"abcd abcd", "permissions": [ "storage","tabs" ], "content_scripts": [ { "matches": ["<all_urls>" ], "js": ["js/content.js","js/jquery.1.8.3.min.js"], "css": ["css/style.css"], "run_at": "document_end", "all_frames": true } ],"web_accessible_resources": [ "img/*.png", "css/*.css" ] }
have considered input field seek doesn't exist time script executes? https://accounts.google.com/
dynamic form, password field created long after page loaded (document_end
) , therefore long after collect inputs
.
in addition binding handler existing elements, need watch new ones being added. suggest using mutation-summary
library query {element: "input[type=password]"}
, if don't want involve library basic building block @ mutationobserver
.
Comments
Post a Comment