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

Playground plugin: Unable to start a sandbox #213

Open
ironnysh opened this issue Apr 3, 2024 · 19 comments · Fixed by #219
Open

Playground plugin: Unable to start a sandbox #213

ironnysh opened this issue Apr 3, 2024 · 19 comments · Fixed by #219
Labels
Bug Something isn't working

Comments

@ironnysh
Copy link
Contributor

ironnysh commented Apr 3, 2024

Hi,
I'm trying to use the Start a sandbox option of the plugin, and ran into a few errors:

  1. First, there was Playground plugin: Show a useful error when the iframe can't be loaded due to CORP mismatch #208, so I added https://playground.wordpress.net/ to my CSP: ✅

  2. Then, I got this: Error: Could not download "https://MYDOMAIN/wp-admin/admin.php?page=playground&download=1".

    • I changed the path in this line from admin_url('admin.php?page=' . PLAYGROUND_ADMIN_PAGE_SLUG), replacing admin.php with tools.php: ✅
  3. Finally, I got a new error: Error: Could not read "/wordpress/schema/_Schema.sql": There is no such file or directory OR the parent directory does not exist.

Not sure how to solve this one :-)

@adamziel
Copy link
Collaborator

adamziel commented Apr 3, 2024

Just to make sure – are you using the latest v0.0.3 release? https://github.com/WordPress/playground-tools/releases/tag/v0.0.3

Looping in @bgrgicak

@adamziel adamziel added the Bug Something isn't working label Apr 3, 2024
bgrgicak added a commit that referenced this issue Apr 5, 2024
Fixes #213 #208

<!-- Thanks for contributing to WordPress Playground Tools! -->

## What?

This PR adds support for exporting Playground data and implements an
error modal when Playground fails to load.

## Why?

We would like to allow users to export snapshots of their sites that can
later be imported into Playground (a feature in Playground isn't
implemented).

Some users reported errors like CORS issues and we need to ensure users
have a next step to debug the issue.

## How?

Playground snapshot is now an option in Tools > Export. 

By catching errors while Playground is loading and displaying an alert. 

## Testing Instructions

<!-- Please include step by step instructions on how to test this PR.
-->
1. Check out the branch.
2. Start a site with the plugin running for example by using wp-env
```
cd packages/playground
wp-env start
```
3. Go to wp-admin > Tools > Export
4. Select _Playground snapshot_ and export it
5. Ensure that the downloaded zip contains data
6. Add one of the headers to the top of `playground.php` 
```
header("Content-Security-Policy: default-src 'self'");

header("Content-Security-Policy: default-src 'self' style-src 'self' 'unsafe-inline' 'unsafe-eval'; script-src 'self' 'unsafe-inline' 'unsafe-eval';");
```
7. Try starting a sandbox
8. Confirm that you see an error alert
@ironnysh
Copy link
Contributor Author

ironnysh commented Apr 5, 2024

Hi @adamziel, apologies: I missed the notification... I was using a version that said 0.0.4 (before this commit).

So, I downloaded and installed v0.0.3 linked in your comment above, and got a new error:
Refused to load blob:https://MYDOMAIN/27719ee4-d593-44c7-9758-327a8181aba1 because it does not appear in the worker-src directive of the Content Security Policy.

I updated the plugin to 0.1.0 (via the WordPress admin), and then the site broke—got "the white screen of death" :-) That's what it says in the error_log file:

[05-Apr-2024 09:17:58 UTC] PHP Warning:  require(/home/MYUSER/MYDOMAIN/wp-content/plugins/playground/src/playground-export.php): Failed to open stream: No such file or directory in /home/MYUSER/MYDOMAIN/wp-content/plugins/playground/playground.php on line 29
[05-Apr-2024 09:17:58 UTC] PHP Fatal error:  Uncaught Error: Failed opening required '/home/MYUSER/MYDOMAIN/wp-content/plugins/playground/src/playground-export.php' (include_path='.:/opt/alt/php80/usr/share/pear:/opt/alt/php80/usr/share/php:/usr/share/pear:/usr/share/php') in /home/MYUSER/MYDOMAIN/wp-content/plugins/playground/playground.php:29
Stack trace:
#0 /home/MYUSER/MYDOMAIN/wp-settings.php(517): include_once()
#1 /home/MYUSER/MYDOMAIN/wp-config.php(100): require_once('/home/MYUSER/...')
#2 /home/MYUSER/MYDOMAIN/wp-load.php(50): require_once('/home/MYUSER/...')
#3 /home/MYUSER/MYDOMAIN/wp-blog-header.php(13): require_once('/home/MYUSER/...')
#4 /home/MYUSER/MYDOMAIN/index.php(17): require('/home/MYUSER/...')
#5 {main}
  thrown in /home/MYUSER/MYDOMAIN/wp-content/plugins/playground/playground.php on line 29

I'm on WordPress 6.5, PHP 8.3.

@bgrgicak
Copy link
Collaborator

bgrgicak commented Apr 5, 2024

@ironnysh could you please update to 0.1.1?
I forgot to add a file to the latest version and it should be fixed now.

@ironnysh
Copy link
Contributor Author

ironnysh commented Apr 5, 2024

Alright, it's working on my local machine. I wonder if it has something to do with the fact that my live site is running in a sub-folder (...MYDOMAIN/wptests...)

@ironnysh
Copy link
Contributor Author

ironnysh commented Apr 5, 2024

@bgrgicak, yay! It doesn't "brake" the site :-)

However, when I go into Tools > Sandbox Site I see a clean install. My changes aren't reflected there.
The console still shows the error I got before:
Error: Could not read "/wordpress/schema/_Schema.sql": There is no such file or directory OR the parent directory does not exist.

@adamziel adamziel reopened this Apr 5, 2024
@bgrgicak
Copy link
Collaborator

bgrgicak commented Apr 5, 2024

yay! It doesn't "brake" the site :-)

Sorry about that 😓

Error: Could not read "/wordpress/schema/_Schema.sql": There is no such file or directory OR the parent directory does not exist.

This error means the SQL export failed. Do you have any errors in your debug.log?

@ironnysh
Copy link
Contributor Author

ironnysh commented Apr 5, 2024

So, latest update :-)

  1. No more error message when running the latest version of the plugin (from the directory).

  2. When I click Tools > Sandbox Site on the live, sub-folder-based site (...MYDOMAIN/wptests...), I get a clean install. My changes aren't reflected.

  3. When I click Tools > Sandbox Site on the live, non sub-folder site, everything works as expected (I got a bunch of other errors, but they might be related to the specific setup I have)

@bgrgicak
Copy link
Collaborator

bgrgicak commented Apr 5, 2024

Thank you for all your feedback, I really appreciate it!

TBH I never tested sites in subfolders. I can take a look at it next week.

@ironnysh
Copy link
Contributor Author

ironnysh commented Apr 5, 2024

Sure thing :-)

No rush... I was just curious about the plugin, so installed it on my experiments site.

@flexseth
Copy link

flexseth commented Apr 5, 2024

Start a sandbox option of the plugin

@ironnysh can you please link to this info? I've been in the docs for almost a week straight and hadn't seen the option for sandbox mode and want to know how it works! Thanks for all you are doing in the space!

@ironnysh
Copy link
Contributor Author

ironnysh commented Apr 6, 2024

Hey @flexseth, it's a feature of the new Playground plugin, which I'm guessing isn't documented yet.

Ditto ;-)

@flexseth
Copy link

flexseth commented Apr 9, 2024

Hey @flexseth, it's a feature of the new Playground plugin, which I'm guessing isn't documented yet.

Ditto ;-)

Wow I've been working on the Playground docs for a week straight now and still find new things :)

Adding it to the list of things to document, a good candidate for the Yoast Contributor Day on April 18th!

@flexseth
Copy link

Tagging Yoast Online Contributor Day to get this mentioned as an issue over there!

@bgrgicak
Copy link
Collaborator

@ironnysh would you have time to take a look at this? I'm not sure when I would be able to prioritize it.

@ironnysh
Copy link
Contributor Author

Hi @bgrgicak, sorry for my late response.

Are we talking about the issue itself or the addition to the documentation? :-)

@bgrgicak
Copy link
Collaborator

I was thinking of the issue When I click Tools > Sandbox Site on the live, sub-folder-based site (...MYDOMAIN/wptests...), I get a clean install. My changes aren't reflected.

@ironnysh
Copy link
Contributor Author

@bgrgicak --I ran another test of the “sub-folder site” in an Incognito window.

  • The themes and plugins are there, but none is activated.
  • The posts, pages, and media aren't there.
  • Changes I make in the Settings menu (wp-admin/options-xxx.php) aren't reflected.

The only error I see in the console is this:
index.js:311 [22-May-2024 14:43:01 UTC] PHP Deprecated: http_build_query(): Passing null to parameter #2 ($numeric_prefix) of type string is deprecated in /internal/shared/mu-plugins/playground-includes/wp_http_fetch.php on line 53

@bgrgicak
Copy link
Collaborator

index.js:311 [22-May-2024 14:43:01 UTC] PHP Deprecated: http_build_query(): Passing null to parameter #2 ($numeric_prefix) of type string is deprecated in /internal/shared/mu-plugins/playground-includes/wp_http_fetch.php on line 53

This error was fixed today WordPress/wordpress-playground#1458
Would you mind taking another look?

What PHP version is that server using?

@ironnysh
Copy link
Contributor Author

I still see this error.

After adding this to the CSP:
worker-src 'self' blob:

I get hundreds of duplicated JS errors (they weren't there before, and fire after the Sandbox tries to execute the SQL):

Event handler of <some> event must be added on the initial evaluation of worker script.
sw.js:53 Event handler of 'message' event must be added on the initial evaluation of worker script.
(anonymous) @ sw.js:53
awaitReply @ sw.js:53
getScopedWpDetails @ sw.js:97
await in getScopedWpDetails (async)
n @ sw.js:53
handleRequest @ sw.js:53
(anonymous) @ sw.js:53

sw.js:53 Event handler of 'message' event must be added on the initial evaluation of worker script.
(anonymous) @ sw.js:53
awaitReply @ sw.js:53
convertFetchEventToPHPRequest @ sw.js:53
await in convertFetchEventToPHPRequest (async)
n @ sw.js:53
await in n (async)
handleRequest @ sw.js:53
(anonymous) @ sw.js:53

What PHP version is that server using?

8.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants