var div = document.querySelector("#content > div");
div.style.width = "800px";
It works when I paste the code into the Browser Console (Safari) and successfully change the width of the div element from "600px" (set by server) to "800px".
However, when I use the following KM action, it does not work:
PS: I have another macro that puts the input box on focus before inserting values. This macro (screenshot below) is applies to the same webpage. It woks flawlessly. (I have a problem with this macro, as indicated in the screenshot below, if I use JavaScript to set the value of the input box, the "Return", which will submit the input, will not work. I can work around this issue by adding the "insert text by typing" action, so this is not a big issue for me. I'm adding this information here not because I want to ask question about this--it would be great if someone can comment on this issue as well--but because, for debugging reason, I want to show that another JavaScript works with the same webpage.)
Edit: the webpage requires login for access. Therefore, I can't post the url here. But it is a Canvas Grading page, in case if anyone else is using Canvas by instructure.com as well.
Edit: here is a screenshot of the code (the "width" attribute in the highlighted section is what I want to change):
As shown above, I have located the parent div element whose id = "content".
However, what follows is different.
This may explain why the KM action does not work.
The "Elements" tab matches the webpage content. The "Sources" tab does not.
So, even if I upload the source code, it will not help.
Any suggestions on how should I proceed?
As I said, although this is a problem, since I have a workaround, it is not a pressing issue to me. I'm not expecting a solution for this problem.
I did come across a post at stackoverflow.com where someone answered that if the iframe source is a different domain, JavaScript injection will be rejected (If I remember correctly, you asked the question in that post). In my case, the source url of the iframe has the same domain. The above JavaScript works for me.
Edit:
I found your question here:
I hope I understood the answer correctly (my comments above), but I have not tested that yet.
Good point. I stand corrected. It appears that JavaScript injection in an iFrame WILL work provided that both the iFrame and the main web page are using the same domain.
I have NOT tested this, but in your use case it seems to work OK: