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

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>17041</bug_id>
          
          <creation_ts>2012-05-12 04:00:46 +0000</creation_ts>
          <short_desc>Setting location before the page is done loading shouldn&apos;t always be a replace load</short_desc>
          <delta_ts>2013-05-31 20:30:25 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WHATWG</product>
          <component>HTML</component>
          <version>unspecified</version>
          <rep_platform>Other</rep_platform>
          <op_sys>other</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://www.whatwg.org/specs/web-apps/current-work/#the-location-interface</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P3</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>Unsorted</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>contributor</reporter>
          <assigned_to name="Ian &apos;Hixie&apos; Hickson">ian</assigned_to>
          <cc>bruant.d</cc>
    
    <cc>bzbarsky</cc>
    
    <cc>ian</cc>
    
    <cc>james</cc>
    
    <cc>mike</cc>
    
    <cc>torisugari</cc>
          
          <qa_contact>contributor</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>67628</commentid>
    <comment_count>0</comment_count>
    <who name="">contributor</who>
    <bug_when>2012-05-12 04:00:46 +0000</bug_when>
    <thetext>Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html
Multipage: http://www.whatwg.org/C#the-location-interface
Complete: http://www.whatwg.org/c#the-location-interface

Comment:
Setting location before the page is done loading shouldn&apos;t always be a replace
load

Posted from: 71.184.125.56 by bzbarsky@mit.edu
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:15.0) Gecko/15.0 Firefox/15.0a1</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>67629</commentid>
    <comment_count>1</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2012-05-12 04:02:01 +0000</bug_when>
    <thetext>See http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2010-July/027372.html for a survey of browser behavior and https://bugzilla.mozilla.org/show_bug.cgi?id=754029#c5 for the reason why the current spec behavior is not really all that great: it makes user interactions race with page loading in undesirable ways.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>70771</commentid>
    <comment_count>2</comment_count>
    <who name="">contributor</who>
    <bug_when>2012-07-18 17:27:41 +0000</bug_when>
    <thetext>This bug was cloned to create bug 18152 as part of operation convergence.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>76742</commentid>
    <comment_count>3</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-10-19 19:29:26 +0000</bug_when>
    <thetext>How about I just make the location.href setter use assign() rather than replace() if there&apos;s a trusted user-interaction event on the stack? (i.e. in response to a click, basically)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>78811</commentid>
    <comment_count>4</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2012-11-26 04:56:30 +0000</bug_when>
    <thetext>I recommend talking this over with &quot;O. Atsushi (Torisugari)&quot; (see linked Mozilla bug), since he&apos;s done a lot of thinking about this recently, including testingof behavior across UAs, compat issues, etc.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82622</commentid>
    <comment_count>5</comment_count>
    <who name="O. Atsushi">torisugari</who>
    <bug_when>2013-02-06 12:19:07 +0000</bug_when>
    <thetext>Hi,

(In reply to comment #3)
&gt; How about I just make the location.href setter use assign() rather than
&gt; replace() if there&apos;s a trusted user-interaction event on the stack? (i.e. in
&gt; response to a click, basically)

Is it easy enough to define &quot;trusted/non-trusted&quot; state in the spec?

For example, if I were a developer working for a search engine like Google or Bing, maybe I want to send HTTP &quot;ping&quot; on every user&apos;s link click. Then I might write such a code:

----- FROM HERE ------
&lt;p&gt;
  Hey, click the search results of your input &quot;Fruits&quot;!

  &lt;a href=&quot;www.examle.com/banana.html&quot;&gt; BANANA! &lt;/a&gt;&lt;/br&gt;
  &lt;a href=&quot;www.examle.com/apple.html&quot; &gt; APPLE!  &lt;/a&gt;&lt;/br&gt;
  &lt;a href=&quot;www.examle.com/orange.html&quot;&gt; ORANGE! &lt;/a&gt;&lt;/br&gt;
  ...
&lt;/p&gt;

&lt;script&gt;
// Try to listen to user&apos;s click...
var anchors = document.getElementsByTagName(&quot;a&quot;)
for (var anchor in anchors) {
  anchor.addEventListener(&quot;click&quot;, clickLink, false);
}

// On &quot;click&quot; evnet by user.
function clickLink(aEvent) {
  event.preventDefault();

  // Don&apos;t redirect at once.
  // Instead, send the url to seach engine&apos;s server.

  var logger = new Image();
  logger.onload = imageLoad;
  logger.src = &quot;http://my.server/logMe?url=&quot; + aEvent.target.href;
}

// On &quot;load&quot; event for dummy 1x1 pixel image.
// Note that this image won&apos;t actually be rendered on the monitor.
function imageLoad(aEvent) {
  // Now we&apos;ve successfully logged the target URL at &quot;my.server&quot;.
  // Start the real redirection.

  var url = aEvent.target.src
                  .replace(&quot;http://my.server/logMe?url=&quot;, &quot;&quot;);

  window.location.href = url;
}
&lt;/script&gt;
----- TO HERE ------

UAs are supposed to trust |location.href| in the &quot;click&quot; handler, since it&apos;s caused by user&apos;s action apparently. But should they trust |location.href| in the &quot;load&quot; handler as well? Well, I&apos;m not talking about just an imaginary case. This problem is described in Mozilla&apos;s bugzilla, and the page has a &quot;setTimeout(...)&quot; version testcase.

https://bugzilla.mozilla.org/show_bug.cgi?id=825544

I don&apos;t know much about DOM3&apos;s |Event::isTrusted|, but it seems we need another more complicated (internal) flag to keep our browser backward-compatible, because the html5 spec does want to make |location.href| &quot;replace()&quot;, in the document&apos;s own &quot;load&quot; listener.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82640</commentid>
    <comment_count>6</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-02-06 20:52:27 +0000</bug_when>
    <thetext>O. Atsushi: So what should the spec say?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82688</commentid>
    <comment_count>7</comment_count>
    <who name="O. Atsushi">torisugari</who>
    <bug_when>2013-02-07 10:27:32 +0000</bug_when>
    <thetext>I have no idea about it, and that&apos;s why my patch for Firefox was backed out. Among the major browsers, only WebKit is handling this issue properly in the way like what you said.

&gt; Interesting, so it seems that Firefox is not taking user gesture into account.
&gt;
&gt; This may be something worth posting to whatwg about for discussion,
https://bugs.webkit.org/show_bug.cgi?id=42861#c12

So as not to confuse web developers, probably we need &quot;standard&quot; way to judge whether or not an event is from user&apos;s action (in WebKit&apos;s terms, &quot;User Gesture&quot;).


Frankly speaking, I&apos;m not yet 100% sure it is really reasonable to change |location.href|&apos;s behavior according to the document&apos;s loading state, though I do understand Gecko&apos;s implementation played an important role when you wrote it into the spec.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86065</commentid>
    <comment_count>8</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-04-12 19:24:41 +0000</bug_when>
    <thetext>Ok well since y&apos;all don&apos;t know what you want the spec to say, if, how about this:

| If any of the following conditions are matched, use assign():
|
| * the Location object&apos;s relevant Document has completely loaded, or
| * in the task in which the algorithm is running, an activation behavior is
|   currently being processed whose click event was trusted, or
| * in the task in which the algorithm is running, the event listener for a
|   trusted click event is being handled.
|
| Otherwise, use replace().</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>88529</commentid>
    <comment_count>9</comment_count>
    <who name="">contributor</who>
    <bug_when>2013-05-31 20:30:17 +0000</bug_when>
    <thetext>Checked in as WHATWG revision r7882.
Check-in comment: Keep pages in history even if they were still loaded when the user navigated away (but still not if a script did it on its own).
http://html5.org/tools/web-apps-tracker?from=7881&amp;to=7882</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>