question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Window did not load after 5000ms

See original GitHub issue

I have two Angular web applications. App_A is like a listener and will set/get the data in its sessionStorage when receiving messages. App_B is like a client and will send message to App_A. App_A and App_B are running in different domains.

At the startup the App_B will try to load App_A into an iframe. The communication was working properly in the past. Recently I upgraded the Angular for v5 to v7 and the latest post-robot. Everything was still working fine when testing in local environment. But after I deployed both App_A and App_B to Azure web services, I got the error “Window did not load after 5000ms” when running App_B in a browser. Also if I only deploy App_A to Azure, and running App_B in the local, everything works fine. Do you have any idea what might be the problem(s)?

// listener.ts

export class StorageListenerService {
    private readListener: any;
    private writeListener: any;
    private clearListener: any;

    constructor() {
        this.init();
    }

    private init(): void {
        try {
            this.readListener = postRobot.on('read', { domain: '*' }, ({ origin, data }) => {
                return { result: this.readStore(data.key) };
            });
        } catch (e) { }

        try {
            this.writeListener = postRobot.on('write', { domain: '*' }, ({ origin, data }) => {
                this.writeStore(data.key, data.value);
            });
        } catch (e) { }

        try {
            this.clearListener = postRobot.on('clear', { domain: '*' }, ({ origin, data }) => {
                this.clearStore(data ? data.key : null);
            });
        } catch (e) { }

    }

    public destroyListener(): void {
        try {
            this.readListener.cancel();
            this.writeListener.cancel();
            this.clearListener.cancel();
        } catch (e) { }
    }

    private readStore(key: string): any {
        const value = window.sessionStorage.getItem(key);
        return value ? JSON.parse(value) : null;
    }

    private writeStore(key: string, value: any): void {
        const serializedData = JSON.stringify(value);
        window.sessionStorage.setItem(key, serializedData);
    }

    private clearStore(key?: string): void {
        if (key) {
            window.sessionStorage.removeItem(key);
        } else {
            window.sessionStorage.clear();
        }
    }

    public setLoginStaff(loginStaff: LoginStaff): void {
        try {
            this.writeStore(StorageKey.loginStaff, loginStaff);
        } catch (e) {
            console.error('write to storage failed.');
        }
    }

    public getLoginStaff(): Promise<LoginStaff> {
        try {
            return Promise.resolve(this.readStore(StorageKey.loginStaff));
        } catch (e) {
            return null;
        }
    }

    public clearLoginStaff(): void {
        try {
            this.clearStore(StorageKey.loginStaff);
        } catch (e) {
            console.error('clear login staff failed.');
        }
    }
}

// client.ts

export class StorageClientService {
    private win: any;
    constructor(@Inject(DOCUMENT) private document: any,
                       @Inject(STORAGE_LISTENER_URL) private StorageListenerUrl: string) {
        this.init();
    }
   
    private init(): void {
        const frame = this.document.createElement('iframe');
        frame.src = this.StorageListenerUrl;
        frame.id = 'childframe';
        frame.name = Math.random().toString();
        frame.onload = null;
        frame.style.visibility = 'hidden';
        this.document.body.appendChild(frame);
        this.win = frame.contentWindow;
    }

    public setLoginStaff(loginStaff: LoginStaff): void {
        try {
        postRobot.send(this.win, 'write',
        { key: StorageKey.loginStaff, value: loginStaff },
        { domain: this.StorageListenerUrl, timeout: 15000 })
        .then(() => {
    }

    public getLoginStaff(): Promise {
        try {
            return postRobot.send(this.win, 'read',
                { key: StorageKey.loginStaff },
                { timeout: 15000 })
            .then(
                ({ data }) => data.result as LoginStaff,
                () => null);
        } catch (e) {
            console.log(e);
            return null;
        }
    }

    public clearLoginStaff(): void {
        try {
            postRobot.send(this.win, 'clear', { key: StorageKey.loginStaff },
                          { domain: this.StorageListenerUrl }).then(() => {
        catch(e) {
            console.error(e);
        }
    }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bluepnumecommented, Feb 28, 2019

window.__postRobot__ is only defined for older versions

0reactions
claustrescommented, Mar 8, 2019

I can confirm the issue about version mismatch even with patch updates, we encountered this one with a parent using 10.0.14 (master) and child using 10.0.10.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Windows 10: Suddenly hard drive runs at 100% Active even at
The average is average 3000-5000ms (up to 2000)+ response time on boot then it falls to 400-500 (up to about 1000ms) after it...
Read more >
Introducing post-robot — smart cross-domain messaging, from ...
Work with Internet Explorer, and enable sending messages between a window and a popup, not just between iframes. How did we achieve all...
Read more >
Error: ChromeDriver did not start within 5000ms - Stack Overflow
I just removed that runner and started fresh one. New Runner downloaded Spectron and ChromeDriver on start and Chrome worked.
Read more >
Forge trying to build files in static folder and failing
After adding ForgeUI from '@forge/ui' to my static app files, the second error disappears but the error related to the esModuleInterop flag ...
Read more >
Source Declarations - Amazon Kinesis Agent for Microsoft ...
By default, Kinesis Agent for Windows can automatically detect the encoding from bytemark. However, the automatic encoding may not work correctly on some ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found