Background
This is due to how the send event works. You can check the onsubmit event on the fiddle here: http://jsfiddle.net/sirhc/VueEJ/
This behavior is due to historical reasons described here on the W3C mailing list .
To get around this, you may need to overwrite your own submit method. And for this you need to add javascript to the page, as content scripts will not be able to access local variables in the content window.
Decision
My solution includes listening to the submit event in the document for a normal form, as well as entering a submit handler to manually fire submit events on the page.
Please note that the JavaScript methods here use the fact that the browser is a modern DOM-compatible browser. Some methods are not available here in versions of IE 8 and lower, but this is great because this code is intended for use in the Chrome extension. May I also suggest not using jQuery and writing my own serialization method.
Despite the fact that I was not requested, I also drew the sender's attention to sending event.preventDefault() .
content.js
document.addEventListener("submit", function (e) { alert('submit hooked!: ' + $(e.target).serialize()); }, false); // Remember to change this to the relative path to inject.js injectScript( chrome.extension.getURL( "/" ), "inject.js" ); function injectScript ( aBasePath, aScriptURL ) { var scriptEl = document.createElement( "script" ); scriptEl.src = aBasePath + aScriptURL; scriptEl.async = false; (document.body || document.head || document.documentElement) .appendChild( scriptEl ); }
inject.js
HTMLFormElement.prototype._nativeSubmit = HTMLFormElement.prototype.submit; HTMLFormElement.prototype.submit = function () { var submitEvent = document.createEvent("HTMLEvents"); submitEvent.initEvent("submit", true, true); if (this.dispatchEvent(submitEvent)) { this._nativeSubmit.apply(this, arguments); } };
manifest.json (added, this is not the whole file)
"web_accessible_resources": [ "inject.js" ]
Adding a manifest allows you to insert the inject.js JavaScript file into the page.
References
sirhc source share