This problem seems to have been sort of resolved, as long as the URL of the page you’re injecting your javascript into starts with www. What do you do if it doesn’t? Here’s the relevant part of my manifest:
"content_scripts": [
{
"run_at": "document_start",
"matches": ["https://groups.google.com/forum/?fromgroups=#!newtopic/opencomments-site-discussions"],
"js": ["postMsg.js"]
}
],
The problem, according to another stackoverflow post, is because the URL of the page doesn’t begin with ‘www’. Does that mean that you can’t inject javascript into secure pages whose URL doesn’t begin with ‘www’, or is there another way? This had never been a problem in the past, because my extension had run with Version 1 manifests.
Forgot to add the content script:
var subject = document.getElementById("p-s-0");
subject.setAttribute("value", "foo");
The element with ID “p-s-0” is the Subject field in the Google Groups Post page, so the field should display “foo”.
A few issues:
That is a not valid match pattern because they only specify up to the URL path (the part before the
?).Change the
matchesto:The overall URL (
https://groups.google.com/forum/?fromgroups=#!newtopic/opencomments-site-discussions) is not practical because Google changes the URL parameters willy nilly. For example,fromgroupsis not often present, and may not have the=if it is. Additional parameters, likehl=encome and go. (This is the reason why my earlier answer worked for me, but not for you.)So, using
include_globsin the manifest would be a messy, error-prone exercise.The solution is to check
location.hashwithin the content script.The script is set to
"run_at": "document_start", so the content script is running before there is any node with idp-s-0.Change the manifest to
"run_at": "document_end".The new Google groups is heavily AJAX driven. So, The “New Topic” page is usually “loaded” without actually loading a whole new page. This means the content script will not rerun. It needs to monitor for “new” AJAX-loaded pages.
Check for “new” pages by monitoring the
hashchangeevent.Additionally, the
p-s-0element is added by AJAX, and is not immediately available on a “new” page. Check for this element within asetInterval.Putting it all together,
The manifest.json becomes:
The content script(postMsg.js) becomes: