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

Links with target="top" don't work #266

Closed
Tracked by #653
georgestephanis opened this issue May 9, 2023 · 3 comments
Closed
Tracked by #653

Links with target="top" don't work #266

georgestephanis opened this issue May 9, 2023 · 3 comments
Labels
[Aspect] Browser [Type] Bug An existing feature does not function as intended

Comments

@georgestephanis
Copy link

Console error when clicking "Activate" after uploading plugin:

Unsafe attempt to initiate navigation for frame with URL 'http://localhost:4400/remote.html?progressbar=true&php=8.0&wp=6.2' from frame with URL 'http://localhost:4400/scope:0.5316310144519707/wp-admin/update.php?action=upload-plugin'. The frame attempting navigation is sandboxed, and is therefore disallowed from navigating its ancestors.
Screenshot 2023-05-09 at 9 13 12 AM

Unsure if it's important or not, but just notating it here in case it turns up later.

@adamziel
Copy link
Collaborator

adamziel commented May 9, 2023

It looks like an <a target="_top"> issue. WordPress is rendered in a sandboxed iframe that prevents top-level navigation. What we really want to do is to target the WordPress iframe, not the top-level window. I'm not sure how to do that other than rewriting all the rendered HTML which I'm not too excited about.

@adamziel
Copy link
Collaborator

I played with the <base> tag without much luck. ChatGPT proposed this not-great-not-terrible fix:

window.addEventListener('DOMContentLoaded', (event) => {
    const iframeDocument = document.querySelector('iframe').contentDocument;

    iframeDocument.addEventListener('click', (event) => {
        if (event.target.tagName === 'A') {
            event.preventDefault();
            iframeDocument.location.href = event.target.href;
        }
    });
});
@adamziel adamziel changed the title Console error when clicking "Activate" after uploading plugin: May 22, 2023
@adamziel adamziel changed the title Links with target="top" don't work. May 22, 2023
@adamziel adamziel added [Type] Bug An existing feature does not function as intended [Aspect] Browser labels May 23, 2023
@adamziel adamziel mentioned this issue Oct 4, 2023
10 tasks
adamziel added a commit that referenced this issue Oct 12, 2023
WordPress is rendered in a sandboxed iframe that prevents top-level navigation.
However, some links in wp-admin, such as the "activate plugin" link
rendered after the plugin is uploaded, are rendered with
target="_parent".

It does not make sense to target the top frame in this context. What we really want
is to target the WordPress iframe.

This commit fixes that via a <script> tag that rewrites the `target` of all
clicked A elements from _top and _parent to wordpress-playground.

Related: #266
adamziel added a commit that referenced this issue Oct 12, 2023
WordPress is rendered in a sandboxed iframe that prevents top-level navigation.
However, some links in wp-admin, such as the "activate plugin" link
rendered after the plugin is uploaded, are rendered with
target="_parent".

It does not make sense to target the top frame in this context. What we really want
is to target the WordPress iframe.

This commit fixes that via a <script> tag that rewrites the `target` of all
clicked A elements from _top and _parent to wordpress-playground.

1. Upload a plugin in wp-admin
2. Click "Activate plugin"
3. Confirm it worked and there are no errors in devtools
4. Play with other wp-admin pages and confirm no previously working links are now broken

Related: #266
adamziel added a commit that referenced this issue Oct 12, 2023
WordPress is rendered in a sandboxed iframe that prevents top-level navigation.
However, some links in wp-admin, such as the "activate plugin" link
rendered after the plugin is uploaded, are rendered with
target="_parent".

It does not make sense to target the top frame in this context. What we really want
is to target the WordPress iframe.

This commit fixes that via a <script> tag that rewrites the `target` of all
clicked A elements from _top and _parent to wordpress-playground.

1. Upload a plugin in wp-admin
2. Click "Activate plugin"
3. Confirm it worked and there are no errors in devtools
4. Play with other wp-admin pages and confirm no previously working links are now broken

Related: #266
adamziel added a commit that referenced this issue Oct 12, 2023
WordPress is rendered in a sandboxed iframe that prevents top-level
navigation. However, some links in wp-admin, such as the "activate
plugin" link rendered after the plugin is uploaded, are rendered with
target="_parent".

It does not make sense to target the top frame in this context. What we
really want is to target the WordPress iframe.

This commit fixes that via a <script> tag that rewrites the `target` of
all clicked A elements from _top and _parent to wordpress-playground.

## Testing instructions

1. Upload a plugin in wp-admin
2. Click "Activate plugin"
3. Confirm it worked and there are no errors in devtools
4. Play with other wp-admin pages and confirm no previously working
links are now broken

Related: #266
@adamziel
Copy link
Collaborator

Fixed in #684

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Aspect] Browser [Type] Bug An existing feature does not function as intended
2 participants