Skip to content
This repository was archived by the owner on Feb 9, 2020. It is now read-only.

Extension causes Angular pages to fail to load after javascript redirect #290

Open
johncrim opened this issue Mar 17, 2016 · 1 comment · May be fixed by angular/angular-hint#120
Open

Comments

@johncrim
Copy link

The attached zip contains two simple pages, start.htm and land.htm. Start.htm redirects the browser to land.htm using javascript (window.location.assign()). Land.htm is a simple angular page that displays a message as to whether angular is successfully loaded or not.

If you open Land.htm directly, it works as expected in any browser (you'll see the "Angular is loaded" text).

If you open start.htm in IE11, or in Chrome with Batarang disabled, you are redirected to land.htm, and you'll see the "Angular is loaded" text - expected behavior.

In Chrome with the AngularJS Batarang extension enabled, and with these pages served from an HTTP server, if you view the start.htm page, you are redirected to land.htm, and you see the "Angular is not loaded" message.

I wasted quite a while figuring out why angular was not loading after a redirect, and it turned out to be caused by this extension.

Batarang hangs Angular.zip

@gkalpak
Copy link
Member

gkalpak commented Mar 18, 2016

This is indeed an issue. The short version is that batarang fails to properly clean up the window name when leaving start.html and as a consequence gets confused when loading land.htm.

The reason is that the clean up is supposed to happen on a beforeunload listener, but the event is not fired if you change the location before the DOM content has been loaded (which is what happens in start.htm).

If you change beforeunload to unload in this line, everything seems to work, because (for whatever reason again) the unload event if fired as expected.

A simple work-around (until this is fixed upstream) is to defer resetting the location, until after the DOM content has been loaded. E.g.:

// In 'start.htm':
setTimeout(function () { location.assign('land.htm'); }, 0);

gkalpak added a commit to gkalpak/angular-hint that referenced this issue Mar 18, 2016
…ent has been loaded

The `beforeunload` event was never fired is the location was changed before the DOM content had
been loaded (e.g. directly inside a `<script>` tag. The `unload` event is fired more consistently.

Fixes angular/batarang#290
gkalpak added a commit to gkalpak/angular-hint that referenced this issue May 2, 2017
…ent has been loaded

The `beforeunload` event was never fired if the location was changed before the DOM content had
been loaded (e.g. directly inside a `<script>` tag). The `unload` event is fired more consistently.
This commit listens for both events to cover more potential browser bugs/edge-cases.

Fixes angular/batarang#290
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants