Since I replied twenty times to myself and probably confused everyone... Let me try to summarise. I think it make sense to<div><br></div><div>1 Test if the approach you suggested works. I think it didn't when I tried but it's certainly worth another try.</div>
<div>2 If load_started doesn't work, send email to the webkitgtk mailing list and see what they suggest.<br><br>Thanks for looking into this, the current implementation is certainly not very nice.<br><br>On Wednesday, 27 November 2013, Rogelio Mita  wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I noticed existence of a WebKitWebView event which is emitted before what any resource be loaded, called <a href="http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#WEBKIT-LOAD-STARTED:CAPS" target="_blank">webkit_loaded_started</a></div>


<div><table border="0" style="padding:4px;margin-left:3em;font-family:cantarell,sans-serif"><tbody><tr><td style="vertical-align:top"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


WEBKIT_LOAD_STARTED: A new load request has been made. No data has been received yet, empty structures have been allocated to perform the load; the load may still fail due to transport issues such as not being able to resolve a name, or connect to a port.</blockquote>


</td><td></td></tr></tbody></table></div><div>I did a concept proof on sugar-toolkit-gtk3 to show this behaviour and the result was:<br></div><div><br></div><div><img src="cid:ii_14297c7e109dbe09" alt="Imágenes integradas 1"><br>


</div><div><br></div><div><div>I think that this behaviour can solve the issue with env.getEnvironment and your hard dependency with sugar var provided by python code.</div><div><br></div><div>This log also show how load_event_finished is executed between successive requests, then there is no doubt about the current problem existence.</div>


<div><br></div><div>You think this may be a solution?, change the script so that it is now run in this event (load_event_started) and rewrite getEnvironment disregarding the possibility that there is no environment variable provided by the Python code, in others words ever when activity is in sugar mode, window.sugar.environment will be present</div>


</div><br clear="all"><div><br></div>-- <br>Roger<div><br><div><a href="http://activitycentral.com/" target="_blank">Activity Central</a></div></div>
</div>
</blockquote></div><br><br>-- <br>Daniel Narvaez<br><br>