So i’m working on a side project which you can view here @ codepen --> https://codepen.io/Mike-was-here123/full/QOEGOj/
(not the best html, but it will do for now)
Here is a run down of how it works to better help answer the question that i will ask. First it obtained the input number of tab from the text box, and runs a for loop that, each interval, opens the current codepen, but on debug mode. This allows the program to close the tab, since you can only close opened pens in debug mode. This is the reason why codepen doesn’t close the current tab when you click on it since your in either editor or full screen mode. Since you did not open the tab you are prevented from closing it.
Opening a codepen maybe 40 codepen tabs can be very slow when done in a couple seconds and cause errors/ crashes. This has led me to the conclusion to open a blank tab (window.open("")), then insert the tab “destruction” ️ code so it closes. How may i accomplish this? Would it be able to know i opened that tab and allow me to close it?
Just in case you skipped that whole entire explanation, my question is how to go about inserting JS code/ script into a blank tab i have opened using a program?
Okay ill disable the tab closing and opening code The loop where i open is at the bottom, just uncomment it from line 20 - 22
I’m not really sure why you want to do something like this, but you can use
document.write() in such a fashion:
var x = window.open('') // open a blank tab;
x.document.write('<script>alert("I was Injected")</script>');
Now this two methods have two problems:
1 - Injecting a script like this will be blocked by basically every server/domain to prevent cross domain attack…
And be thankful because otherwise I could insert in my website a script that looks into your open tabs, and if I find something interesting there I’d inject a nice script to take what I want from there
2- I believe that
document.write will cancel everything on a page if the script loads after said page.
But I’ll let you look at the documentation for additional info.
In conclusion what you want to achieve may be done if you were the server owner, and accept script incoming from a page of your own domain ( but still…)
On Codepen… I really don’t know
For some reason when i go to inject code i cant put a closing tag
</script> or it just inserts my JS code from their on out into my current html.
This was the code i used:
var src= "jquery-3.2.1.min.js"
Doesn’t work? If i check the inspect of the blank tab it is present.
So any idea on why the tab wont close?
I came accross and new function which you can view Here
var x = window.open("")
I think this is a start, still not working though. Any ideas?
So how would i go about inserting code into a newly opened
about:blank tab? I already tried
Just tried this on Chrome and worked, perhaps you are making some syntax mistake?
This was the issue i’m getting with that. It wont even let my run my loop either.
I was able to make that code run from the Browser’s console, however looks to me that CodePen is sanitising the code you write to prevent malicious code to be run.
As I told you last time, trying to do this kind of operation is always risky since it’s borderline with script injection.
You may have an easier time If you try to run the code on your own domain
EDIT: I suspect is CodePen conflicting with the
script tag because this works as expected.
var x = window.open('');
Perhaps there’s something in their documentation that can help you further
For some reason it goes in, yet it just wont run.
EDIT: I suspect is CodePen conflicting with the script tag because this works as expected.
That is exactly was i suspected too. I was able to do what i am talking about with my own codepen. I would open it in debug mode, and since my codepen contains a
self.close() command it will close once it is opened. This caused lag after a couple hundred tabs compared to a blank tab.