<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>19922</bug_id>
          
          <creation_ts>2008-07-07 00:58:26 -0700</creation_ts>
          <short_desc>image doesn&apos;t get fetched when requested from an onunload handler.</short_desc>
          <delta_ts>2011-02-22 14:24:34 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>New Bugs</component>
          <version>312.x</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://homepage.mac.com/jorgechamorro/cljs/002/</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P1</priority>
          <bug_severity>Major</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Jorge">jorgechamorro</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ap</cc>
    
    <cc>beidson</cc>
    
    <cc>burcujdogan</cc>
    
    <cc>fishd</cc>
    
    <cc>gkumarrahul</cc>
    
    <cc>info.varghese</cc>
    
    <cc>japhet</cc>
    
    <cc>jorgechamorro</cc>
    
    <cc>rob+webkit</cc>
    
    <cc>sedgar</cc>
    
    <cc>stevo10018</cc>
    
    <cc>tflynn25</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>85309</commentid>
    <comment_count>0</comment_count>
    <who name="Jorge">jorgechamorro</who>
    <bug_when>2008-07-07 00:58:26 -0700</bug_when>
    <thetext>An image is requested from the onunload handler, but the img request never gets to the (src=) server. Onunload img loading behaviour is different depending on wether the page gets closed, you&apos;re navigating away, or the onunload handler gets called as a function (). The same code that fails in Safari, works fine in FF and Opera, etc. The idea is to track when a user leaves a page. Looks like if the same thing happens when the request if for a &lt;script&gt; instead of an &lt;img&gt;. See the complete description of the problem in comp.lang.javascript thread &quot;unload event more restrictive now on Safari 3.1&quot;. Thanks, Jorge.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85312</commentid>
    <comment_count>1</comment_count>
      <attachid>22123</attachid>
    <who name="Stevo">stevo10018</who>
    <bug_when>2008-07-07 01:54:56 -0700</bug_when>
    <thetext>Created attachment 22123
Simple test page showing the unload restrictive behavior

This simple test page shows that if you call a function from a form button, then that function is allowed to make http requests for an image into a Javascript image object. That same function when called from an unload handler (or a beforeunload handler) are apparently being blocked from doing that. Adding an alert into the unload function shows that the unload event is calling the function, it&apos;s just being prevented from making the http requests it wants to.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85313</commentid>
    <comment_count>2</comment_count>
    <who name="Stevo">stevo10018</who>
    <bug_when>2008-07-07 01:59:00 -0700</bug_when>
    <thetext>It seems like the actions of an unload/beforeunload handler have been &quot;sandboxed&quot; to prevent any http requests. This breaks a lot of web pages that wish to track how long a page was active and what actions were taken on it.

This behavior is allowed on all versions of IE, Firefox, Netscape, Mozilla, Opera, and all versions of Safari up to 3.0.4. It&apos;s only the launch of Safari 3.1 where this behavior became broken (or deliberately restricted).

In addition to hoping this bug gets fixed, there are a number of us web developers that need a workaround if one is possible. Having it fixed in a nightly build doesn&apos;t help us between now and the time of the next Safari release.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85315</commentid>
    <comment_count>3</comment_count>
    <who name="krg">gkumarrahul</who>
    <bug_when>2008-07-07 03:33:36 -0700</bug_when>
    <thetext>Plus I have been trying to send along a query string formatted in javascript and sent using a XHR POST request to the server and that doesn&apos;t get sent either. So in summary, any http requests are not completing in any unload event handler.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85320</commentid>
    <comment_count>4</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2008-07-07 04:35:07 -0700</bug_when>
    <thetext>(In reply to comment #2)
&gt; It seems like the actions of an unload/beforeunload handler have been
&gt; &quot;sandboxed&quot; to prevent any http requests.

Could you please file a separate bug for onbeforeunoad?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85346</commentid>
    <comment_count>5</comment_count>
    <who name="Jorge">jorgechamorro</who>
    <bug_when>2008-07-07 08:51:53 -0700</bug_when>
    <thetext>(In reply to comment #3)
&gt; Plus I have been trying to send along a query string formatted in javascript
&gt; and sent using a XHR POST request to the server and that doesn&apos;t get sent
&gt; either. So in summary, any http requests are not completing in any unload event
&gt; handler.

Did you make it a synchronous XHR ?
The (GET, synchronous) XHR in the example URL seems to work : see : http://homepage.mac.com/jorgechamorro/cljs/002/
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85353</commentid>
    <comment_count>6</comment_count>
    <who name="krg">gkumarrahul</who>
    <bug_when>2008-07-07 10:17:38 -0700</bug_when>
    <thetext>(In reply to comment #5)
&gt; (In reply to comment #3)
&gt; &gt; Plus I have been trying to send along a query string formatted in javascript
&gt; &gt; and sent using a XHR POST request to the server and that doesn&apos;t get sent
&gt; &gt; either. So in summary, any http requests are not completing in any unload event
&gt; &gt; handler.
&gt; 
&gt; Did you make it a synchronous XHR ?
&gt; The (GET, synchronous) XHR in the example URL seems to work : see :
&gt; http://homepage.mac.com/jorgechamorro/cljs/002/
&gt; 

This example does indeed work. But is a sync call ok when someone is trying to navigate away from a page?? Although for the purpose i am using[recording time spent on a page, by sending the time spent to the server, when a user exits a page], i won&apos;t send any response to the browser, does that affect any client thread/process waiting for any response, in any version??
So far the example provided by Jorge has worked really well, even for &apos;onbeforeunload&apos;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85378</commentid>
    <comment_count>7</comment_count>
    <who name="Stevo">stevo10018</who>
    <bug_when>2008-07-07 12:46:02 -0700</bug_when>
    <thetext>(In reply to comment #5)
&gt; Did you make it a synchronous XHR ?
&gt; The (GET, synchronous) XHR in the example URL seems to work : see :
&gt; http://homepage.mac.com/jorgechamorro/cljs/002/

Thanks for that workaround Jorge. It may end up being all we can do, but for now, I&apos;m going to wait to see how this bug is handled. The webkit team might say &quot;yes indeed we did actively stop unload handlers from making image requests&quot;, in which case we&apos;re probably forced to use that workaround, unless they block that too. Or they might just say it&apos;s a bug that will be fixed in Safari 3.2 which is due in X number of weeks. If this is the case, then I&apos;ll be happy enough to not worry about it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85780</commentid>
    <comment_count>8</comment_count>
    <who name="Stevo">stevo10018</who>
    <bug_when>2008-07-11 08:45:57 -0700</bug_when>
    <thetext>Any chance of changing the priority? Bugzilla won&apos;t let me because I&apos;m not the owner or reporter. Maybe it&apos;ll force someone to take a look. There are a bunch of us that really need this fixing before the next release of Safari.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85782</commentid>
    <comment_count>9</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2008-07-11 09:34:56 -0700</bug_when>
    <thetext>As mentioned above, please file a separate bug for onbeforeunload.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85890</commentid>
    <comment_count>10</comment_count>
    <who name="Stevo">stevo10018</who>
    <bug_when>2008-07-14 07:41:25 -0700</bug_when>
    <thetext>(In reply to comment #9)
&gt; As mentioned above, please file a separate bug for onbeforeunload.

That won&apos;t help anything, it&apos;ll just be marked as a duplicate.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>97367</commentid>
    <comment_count>11</comment_count>
    <who name="Stevo">stevo10018</who>
    <bug_when>2008-11-01 05:18:20 -0700</bug_when>
    <thetext>(In reply to comment #10)
&gt; (In reply to comment #9)
&gt; &gt; As mentioned above, please file a separate bug for onbeforeunload.
&gt; That won&apos;t help anything, it&apos;ll just be marked as a duplicate.

Really useful logging bugs here I see.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>99510</commentid>
    <comment_count>12</comment_count>
    <who name="T Flynn">tflynn25</who>
    <bug_when>2008-11-20 11:15:49 -0800</bug_when>
    <thetext>I have also been trying to figure this out for the past 3 days. Finally found this bug report.

The desired behavior is not all that uncommon.  Oftentimes developers want to know how long a visitor was on the page.  Without being able to create an image or use AJAX, there really isn&apos;t much else.

I am happy to have found Jorge&apos;s workaround.  Is there any word on this issue?  I would prefer not to use a workaround.  What is the purpose of this restriction?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>99521</commentid>
    <comment_count>13</comment_count>
    <who name="T Flynn">tflynn25</who>
    <bug_when>2008-11-20 11:44:26 -0800</bug_when>
    <thetext>The behavior is also occurring in Google Chrome since it is also using WebKit.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>181243</commentid>
    <comment_count>14</comment_count>
    <who name="Sergii">sedgar</who>
    <bug_when>2010-01-15 08:49:27 -0800</bug_when>
    <thetext>Just want to send small ping (Ajax request) to statistic service when user leave my page.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>209780</commentid>
    <comment_count>15</comment_count>
    <who name="Burcu Dogan">burcujdogan</who>
    <bug_when>2010-04-07 12:28:36 -0700</bug_when>
    <thetext>This is absolutely a high priority bug since metric capturing code should invoke the bound function whenever user is navigating out of the page.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>212647</commentid>
    <comment_count>16</comment_count>
    <who name="ajay">info.varghese</who>
    <bug_when>2010-04-14 16:22:57 -0700</bug_when>
    <thetext>Just desperate to get a solution for this issue. Here is a workaround I came up with. Like to share with you all.
It works cross site for browser Safari, Chrome, IE, &amp; firefox. Should work with other browser too.
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;script type=&quot;text/javascript&quot;&gt; 
function imageget() {
	im = new Image()
	im.src=&quot;http://example.com/foo.gif&quot;;
	setTimeout(&apos;document.myform.submit()&apos;, 100);
};
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form name=&quot;myform&quot;&gt;
&lt;input class=&quot;submit&quot; id=&quot;but1&quot; type=&quot;submit&quot; value=&quot;Click Me&quot; onclick=&quot;imageget();return false;&quot; /&gt;
&lt;/form&gt;
&lt;/body&gt;

here i am tricking safari by breaking the current call stack by returning false and making a  asynchronous call for the submit using setTimeout. 
Thanks
Ajay</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>286256</commentid>
    <comment_count>17</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2010-09-28 08:29:14 -0700</bug_when>
    <thetext>Fixed in bug 30457?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>286267</commentid>
    <comment_count>18</comment_count>
    <who name="Nate Chapin">japhet</who>
    <bug_when>2010-09-28 08:44:28 -0700</bug_when>
    <thetext>(In reply to comment #17)
&gt; Fixed in bug 30457?

Yes, 30457 should have resolved this. (http://trac.webkit.org/changeset/65910)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>355550</commentid>
    <comment_count>19</comment_count>
    <who name="Rob O&apos;Brien">rob+webkit</who>
    <bug_when>2011-02-22 13:19:33 -0800</bug_when>
    <thetext>This doesn&apos;t seem to be resolved (tested in 533.19.4). The &quot;Simple test page&quot; attachment displays the same behavior as originally described. Can this be reviewed?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>355554</commentid>
    <comment_count>20</comment_count>
    <who name="Nate Chapin">japhet</who>
    <bug_when>2011-02-22 13:31:30 -0800</bug_when>
    <thetext>(In reply to comment #19)
&gt; This doesn&apos;t seem to be resolved (tested in 533.19.4). The &quot;Simple test page&quot; attachment displays the same behavior as originally described. Can this be reviewed?

How are you testing it?  Using the Chrome dev channel (WebKit r78450 I believe), I see the request being sent to the network, so I&apos;m interested to know what we&apos;re doing differently :)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>355556</commentid>
    <comment_count>21</comment_count>
    <who name="Nate Chapin">japhet</who>
    <bug_when>2011-02-22 13:34:48 -0800</bug_when>
    <thetext>(In reply to comment #20)
&gt; (In reply to comment #19)
&gt; &gt; This doesn&apos;t seem to be resolved (tested in 533.19.4). The &quot;Simple test page&quot; attachment displays the same behavior as originally described. Can this be reviewed?
&gt; 
&gt; How are you testing it?  Using the Chrome dev channel (WebKit r78450 I believe), I see the request being sent to the network, so I&apos;m interested to know what we&apos;re doing differently :)

Wait, never mind.  I just checked the Safari branches in http://trac.webkit.org/browser/branches, and it looks like the relevant patch didn&apos;t get picked up until 534.x builds.  This isn&apos;t expected to work in 533.19.4.

Sorry for not checking the version numbers before posting.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>355604</commentid>
    <comment_count>22</comment_count>
    <who name="Rob O&apos;Brien">rob+webkit</who>
    <bug_when>2011-02-22 14:24:34 -0800</bug_when>
    <thetext>(In reply to comment #21)

This makes sense. I just tested Chrome/534 and it works as expected. I appreciate the quick response.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>22123</attachid>
            <date>2008-07-07 01:54:56 -0700</date>
            <delta_ts>2008-07-07 01:54:56 -0700</delta_ts>
            <desc>Simple test page showing the unload restrictive behavior</desc>
            <filename>unloadtest.html</filename>
            <type>text/plain</type>
            <size>707</size>
            <attacher name="Stevo">stevo10018</attacher>
            
              <data encoding="base64">PGh0bWw+PGJvZHk+DQo8YSBocmVmPSJ1bmxvYWR0ZXN0Lmh0bWwiPmNsaWNrIHRvIG5hdmlnYXRl
IGF3YXkgKGFuZCBjYXVzZSB1bmxvYWQgZXZlbnQpPC9hPg0KPHNjcmlwdD4NCnZhciBzdGFydGVk
PW5ldyBEYXRlKCkuZ2V0VGltZSgpOw0KdmFyIGltajsNCmZ1bmN0aW9uIG15dW5sb2FkZnVuYygp
DQp7DQoJdmFyIGRpZmY9KG5ldyBEYXRlKCkuZ2V0VGltZSgpLXN0YXJ0ZWQpLzEwMDA7DQoJaW1q
PW5ldyBJbWFnZSgpOw0KCXZhciB1PSJodHRwOi8vZXhhbXBsZS5jb20vdGltZS5naWY/IitkaWZm
Ow0KCWltai5zcmM9dTsNCglkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgib3V0cHV0ZGl2IikuaW5u
ZXJIVE1MKz0oInJlcXVlc3RlZCAiK3UrIjxicj4iKTsNCn0NCmlmKHdpbmRvdy5hZGRFdmVudExp
c3RlbmVyKQ0KCXdpbmRvdy5hZGRFdmVudExpc3RlbmVyKCd1bmxvYWQnLG15dW5sb2FkZnVuYyxm
YWxzZSk7DQplbHNlIGlmKHdpbmRvdy5hdHRhY2hFdmVudCkNCgl3aW5kb3cuYXR0YWNoRXZlbnQo
J29udW5sb2FkJyxteXVubG9hZGZ1bmMpOw0KPC9zY3JpcHQ+DQo8Zm9ybT4NCgk8aW5wdXQgdHlw
ZT1idXR0b24gdmFsdWU9ImNsaWNrIG1lIHRvIHByb3ZlIG15dW5sb2FkZnVuYyBmdW5jdGlvbiIg
b25jbGljaz0ibXl1bmxvYWRmdW5jKCkiPg0KPC9mb3JtPg0KPGRpdiBpZD0ib3V0cHV0ZGl2Ij48
L2Rpdj4NCjwvYm9keT48L2h0bWw+DQo=
</data>

          </attachment>
      

    </bug>

</bugzilla>