Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visual sandboxing breaks the global window variable #38

Closed
Knagis opened this issue Oct 4, 2016 · 3 comments
Closed

Visual sandboxing breaks the global window variable #38

Knagis opened this issue Oct 4, 2016 · 3 comments
Labels

Comments

@Knagis
Copy link

Knagis commented Oct 4, 2016

Probably due to something related to the visual sandboxing, the window global variable becomes somewhat unusable.

For example, window.addEventListener() throws an exception (TypeError: Invalid calling object on Edge, TypeError: Illegal invocation on Chrome).

    export class Visual implements IVisual {
        constructor(options: VisualConstructorOptions) {
            console.log("window === window.window", window === window.window);

            try {
                window.addEventListener("click", function(e){console.log("1")});
            } catch (e) {
                console.error('window.addEventListener("click", function(e){});', e);
            }

            try {
                window.window.addEventListener("click", function(e){console.log("2")});
            } catch (e) {
                console.error('window.window.addEventListener("click", function(e){});', e);
            }
        }
    }
@raananzvi
Copy link
Contributor

Visuals are hosted inside a sandboxed IFRAME with only allow-scripts enabled see: http://www.w3schools.com/tags/att_iframe_sandbox.asp
It might be the reason.
Why do you need to add event listener on the window in the first place?

@Knagis
Copy link
Author

Knagis commented Oct 13, 2016

The sandbox attribute does not cause this behavior.

sandbox.html

<!DOCTYPE html>
<html>
<body>
<iframe style="width: 100%; height: 300px" sandbox="allow-scripts" src="sandbox-inner.html"></iframe>
</body>
</html>

sandbox-inner.html

<!DOCTYPE html>
<html>
<body>
<div id="result"></div>
<script>
    var result = document.getElementById("result");
    try {
        window.addEventListener("click", function(e){result.innerHTML = "works"});
    } catch (e) {
        result.innerHTML = 'error: ' + e;
    }
</script>
</body>
</html>

As for the need for this - our library attaches to certain mouse events on the window so that it can process them while the pointer is outside of its own elements.

@raananzvi
Copy link
Contributor

After we discussed I was able to pin point the issue in Power BI codebase.
I submitted a fix and it will take some time until it will arrive to production (several weeks).
Closing the issue for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants