GithubHelp home page GithubHelp logo

Basic example doesn't work about jailed HOT 15 OPEN

asvd avatar asvd commented on August 24, 2024
Basic example doesn't work

from jailed.

Comments (15)

mp31415 avatar mp31415 commented on August 24, 2024 1

It may be obvious but in addition to jailed.js all other files from lib folder must be also available. If these files are around the basic example works.

from jailed.

asvd avatar asvd commented on August 24, 2024

And what happens then? Is there some error message on the console?

from jailed.

mgeduld avatar mgeduld commented on August 24, 2024

Sorry. I should have specified. I get this Error message: Uncaught TypeError: Cannot read property 'foo' of null

And when I dump plugin into the console, remote's value is null.

from jailed.

asvd avatar asvd commented on August 24, 2024

I see, the plugin takes some time to initialize and it happens asynchronously. When you just created the Plugin instance with new jailed.Plugin(pluginCode, api);, the connection to the plugin is not yet ready at the same moment, so you cannot simply invoke plugin.remote.foo() right after creation.

Instead, use the whenConnected() one-off event to postpone the usage upon the plugin initialization. This can be achieved by replacing your last line of code with something like:

var start = function() {
    plugin.remote.foo();
}

plugin.whenConnected(start);

from jailed.

mgeduld avatar mgeduld commented on August 24, 2024

That make sense, but this still doesn't work. The error is gone, but I neither get an alert nor the "started" message in the console.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="jailed.js"></script>
</head>
<body>
    <div id="content"></div>
    <script>
        var api = {
            alert: alert
        };

        var pluginCode = "application.setInterface({\n";
        pluginCode += "foo: function() {\n";
        pluginCode += " application.remote.alert('hi');\n";
        pluginCode += "}});"

        console.log(pluginCode);


        var plugin = new jailed.Plugin(pluginCode, api);

        plugin.whenConnected(function() {
            console.log('started');
            plugin.remote.foo();
        });
    </script>
<body>
</html>

from jailed.

asvd avatar asvd commented on August 24, 2024
  1. which version of jailed do you use? (from the release, or from the repo?)
  2. Does it work if launched from a web-server, and not locally? (I am not sure if it should work locally at all...)

from jailed.

mgeduld avatar mgeduld commented on August 24, 2024

I used 0.2.0.

I haven't tried it from a server. The documentation made it seem as if it could work as a client-only app, but maybe I misunderstood it.

from jailed.

asvd avatar asvd commented on August 24, 2024

It is indeed a client-only app, but there are some security restricitons of the browser arising when you launch it from a local filesystem. It should (in theory) work locally as well, otherwise there is a bug. Can you please try to use the recent sources from the repository, in order to see if the problem is not yet fixed?

from jailed.

mgeduld avatar mgeduld commented on August 24, 2024

The latest version still says it's 0.2.0. Did you make changes without bumping the number?

from jailed.

mgeduld avatar mgeduld commented on August 24, 2024

I just downloaded the distribution again and tried it on a different Mac. It doesn't work in Chrome, and no errors appear in the console.

It also doesn't work in Safari, but I see this: [Error] SyntaxError: DOM Exception 12: An invalid or illegal string was specified. (_pluginWeb.js, line 50)

from jailed.

mgeduld avatar mgeduld commented on August 24, 2024

Firefox: An iframe which has both allow-scripts and allow-same-origin for its sandbox attribute can remove its sandboxing. index.html
The character encoding of a framed document was not declared. The document may appear different if viewed without the document framing it.

from jailed.

asvd avatar asvd commented on August 24, 2024

The latest version still says it's 0.2.0. Did you make changes without bumping the number?

Yep, this is what I ment. There are a lot of changes committed to the repo but not yet released. Please go here: https://github.com/asvd/jailed and click "Download zip" button, you will get the fresh sources.

from jailed.

mgeduld avatar mgeduld commented on August 24, 2024

I did that and got the above errors.

from jailed.

asvd avatar asvd commented on August 24, 2024

Another issue in your code: if you initialize a plugin out of a string, it should be DynamicPlugin, not a Plugin (which is used when code is stored in a file). Your example works for me locally with such a fix.

from jailed.

aminroosta avatar aminroosta commented on August 24, 2024

@asvd Even with DynamicPlugin i get Cannot read property 'foo' of null.

from jailed.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.