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

Pass values to jailed code #58

Open
scattered opened this issue Jun 23, 2022 · 2 comments
Open

Pass values to jailed code #58

scattered opened this issue Jun 23, 2022 · 2 comments

Comments

@scattered
Copy link

I'm sure I'm missing something obvious, but how do I go about passing an object of key / value pairs to the jailed code?

For example, if I had something like:

{
  firstName: John,
  lastName: Doe
}

How would I go about accessing firstName and lastName within plugin.js? My original guess was that I'd add the object to the 2nd property of jailed.Plugin(pathToPlugin, { scope: { firstName: 'John', lastName: 'Doe' } }) but it didn't work.

I looked at the web-banner example in the repo, but the bad / good image names are hardcoded into plugin.js. I need those values to be dynamic.

@eric-hemasystems
Copy link

eric-hemasystems commented Jun 29, 2022

I'm using the dynamic plugin so YMMV but what I do is have my script export a function called run that then the host calls. Something like this:

import { DynamicPlugin as sandbox } from 'jailed'

const boilerplate = `
  application.setInterface({
    // Function called by app to start script
    run: async (data, done) => {
      .... script to run ....

      done()
    }
  })
`

const process = new sandbox(boilerplate, callbacks)

return new Promise(resolve => {
  process.whenConnected(()=> {
    process.remote.run({ ...data to pass.... }, resolve)
  })
})

You could also just serialize the data and embed in your dynamic script.

@scattered
Copy link
Author

Thanks for the example. It looks to be working.

Serializing the data was my first thought, but thought there should be a better solution (such as what you provided).

Thanks again.

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

No branches or pull requests

2 participants