javascript - Preventing Gmail From Closing / Keeping It Visible -


disclaimer before uppity types start in: not deployed "in wild". local, personal use chrome add-on only. not trying trick visitors sites or else unsavory. i've seen bit of chastising of wanting hook onbeforeunload.

some background

far , away biggest gripe chrome (at least on mac os) tab close buttons which, when have several tabs open (as do), results in closing tabs unintentionally tabs become small , click target area isn't covered tab close button small. on tabs news stories, blog posts, documentation, etc. it's annoying not huge inconvenience. cmd+t reopen tab , there's no real harm done. however, tabs, in particular gmail, have definite downsides being closed. have 1 or more chat dialogs coworkers open , reopening tab not restore chat dialog, , initiating new chat loses me current chat history (yes, it's saved, it's not conveniently accessible scrolling backwards in context). there handful of requests google add option remove tab close buttons (i prefer use cmd+w myself), i'm not holding breath on that.

a partial solution

a while friend pointed me towards dotjs chrome add-on allows per-domain custom javascript execution, akin greasemonkey, different. @ rate, gave me means "fix" issues/wants on number of sites visit regularly, , i've found helpful far. other day occurred me keep gmail, et al tab(s) open bit of javascript. threw small script based on regular expression prompt before closing tab. gist of code follows:

var unloadhandler = function(e) {     if (/(mail.google.com|google.com\/reader|gmail.com)/.test(location)) {         return 'are sure want close: ' + location.host;     } };  window.onbeforeunload = unloadhandler; 

lo , behold, did trick of sites tried on; except one: gmail. let me correct that: worked, insofar prompted me confirm closing of gmail tab, , if opted not close it, keep tab open, before dialog prompted me, page had gone white. element inspector shows markup still there (so far can tell), , styles on elements shouldn't hiding things (i.e. display: none; visibility: hidden; etc) , elements' positioning still correct (e.g. they're within viewable area). went through one-by-one removing elements see if obscuring gmail interface, never able reveal on screen. cannot life of me figure out what's going on. i'm not sure if gmail hooked event i'm unaware of (an on*before*beforeunload?), or if google's browser doing special gmail page, or causing strange behavior. google reader unaffected oddity (i can prevent close , retain contents of page) of other sites i've tested with.

does know might causing issue?

for record, running following: mac os x 10.6.5, google chrome 10.0.648.205, , dotjs 1.3.

i appreciate feedback, not looking solutions involve: pinning tabs, changing workflow/usage (e.g. not selecting tabs mouse), etc. want figure out what, specifically, gmail (or perhaps chrome?) doing sabotaging efforts here. in advance.

i think gmail's own code causes behavior. can reproduce problem (on linux machine) subscribing event console function

window.onbeforeunload = function(e) {     return "hey what\'s wrong you?!"; }; 

after i've started developer tool profiler, last call after closing window (and choose 'stay on page' answer question) removechild function call, removes content <iframe id="canvas_frame" />. content elements not there anymore.

function fc(b) {     return b && b.parentnode ? b.parentnode.removechild(b) : m } 

i've found 'traces' in obfuscated code subscribing beforeunload event, it's hard sure :)

function it(b, a) {     this.qc = jca++;     this.ea = b;     this.ka = new j(this);     this.qa = a;     this.ka = [];     this.za = !1;     this.ka.ya(this.ea, "unload", this.da);     this.ka.ya(this.ea, "beforeunload", this.ab);     ypa(zd(a), this);     this.ia() } 

i tried reproduce behavior in firefox think google ships different javascript codes different browsers can't reproduce it.


Comments