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

Support LiveCodes #28

Closed
hatemhosny opened this issue Aug 14, 2023 · 12 comments
Closed

Support LiveCodes #28

hatemhosny opened this issue Aug 14, 2023 · 12 comments

Comments

@hatemhosny
Copy link
Contributor

This is a very nice project. Thank you.
And Codeium is, of course, very useful indeed.

I'm the author of LiveCodes, a feature-rich, open-source, client-side code playground that supports 80+ languages/frameworks. Please read the announcement.

LiveCodes also allows embedding playgrounds in webpages using a powerful SDK.

I'm interested in adding support for LiveCodes to your project.

LiveCodes allows the user to select from 3 code editors:

  • Monaco editor (currently v0.40.0): This is the default editor on desktop.
  • CodeMirror 6: The default editor on mobile.
  • CodeJar (currently v4.1.1): The editor used in lite mode

The user may select the editor from editor settings or configuration options (if using the SDK).

I understand, that currently of these editors, you only support Monaco editor, which is fine with me. In my use-case, this will be the most commonly used editor.

The implementation of the code editors can be found here.

I would be interested to help providing the integration.

@pqn
Copy link
Contributor

pqn commented Aug 14, 2023

If you're using Monaco already, does the extension work if you just add your domain to the allowlist setting?

@hatemhosny
Copy link
Contributor Author

No, it doesn't

@pqn
Copy link
Contributor

pqn commented Aug 14, 2023

As mentioned in #9, the main Monaco compatibility issues are usually:

The issue here is generally that the Monaco version being used is too old, or webpack is pruning the required inline completion features since they aren't being used by the website themselves.

Do those apply to you?

@hatemhosny
Copy link
Contributor Author

I'm using a relatively new Monaco editor version (v0.40.0) and I'm not using webpack.

However, the page which hosts the editors is in an iframe whose content is dynamically written using iframe.contentWindow.document.write

https://github.com/live-codes/livecodes/blob/cdd3959f0c59b24956f6936141c9f460c1f0c31b/src/livecodes/main.ts#L75

So may be that's why the domian list does not work.
Can I work around that?

@pqn
Copy link
Contributor

pqn commented Aug 14, 2023

You could try adding a

<meta name="codeium:type" content="monaco">

and add detection support for this where we check the allowlist:

if (host.test(window.location.href)) {

@hatemhosny
Copy link
Contributor Author

Do you mean open a PR with something like this?

if (host.test(window.location.href) || document.querySelector('meta[name="codeium:type"]')) {
...

@pqn
Copy link
Contributor

pqn commented Aug 14, 2023

Yes, if you can verify that a solution like that works for your setup, then we could accept such a change.

@hatemhosny
Copy link
Contributor Author

Thank you.
I will try that and let you know.

@hatemhosny
Copy link
Contributor Author

Yes, the meta tag approach worked without having to add the domain to the allowlist. Thank you.

However, I did need to change the way I loaded the page probably due to CSP. See details here: live-codes/livecodes#409

My app is open-source, and it allows self-hosting. So, the meta tag approach suits me a lot more.

I will open a PR with this change. I just have one question.
If we need to add this meta tag:

<meta name="codeium:type" content="monaco">

What happens if we need to support more than one editor (e.g. Monaco and CodeMirror)?
do we need to add another meta tag? or should we just keep the tag more generic?

@pqn
Copy link
Contributor

pqn commented Aug 15, 2023

I'm picturing the content value is a comma-separated list of opt-in injections we're requesting basically.

pqn pushed a commit that referenced this issue Aug 16, 2023
* allow running in web pages using a meta tag

if a web page needs to run the extension without being in the allowlist, this meta tag would trigger activating the functionality of the extension:

```
<meta name="codeium:type" content="monaco">
```

see #28

* add TODO comment for injection types
@hatemhosny
Copy link
Contributor Author

Thank you.
This has been solved with #29

Please let us know when the new release is published so that LiveCodes users can use it.

Thank you, indeed.

@pqn
Copy link
Contributor

pqn commented Aug 18, 2023

This should be published now.

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