Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 18, 2025

Intercepts window.open() calls and target="_blank" links within proxied content to navigate the main iframe instead of opening new tabs, keeping users within the proxy environment.

Changes

Three-layer interception approach:

  1. Service worker HTML injection (public/sw.js)

    • Injects script into all proxied HTML responses from UV/Scramjet
    • Runs before page scripts, ensuring early interception
  2. Global window.open override (src/pages/index.astro)

    • Inline script overrides window.open() before module loading
    • Fallback for content not caught by service worker
  3. Iframe load handler (src/pages/index.astro)

    • Injects script on iframe load events
    • Additional safety layer with comprehensive logging

Interception mechanism:

// Injected script captures window.open and link clicks
window.open = function(url, target, features) {
    if (url && window.parent !== window) {
        window.parent.postMessage({
            type: 'navigate-iframe',
            url: url.toString()
        }, '*');
        return null;  // Prevent new window
    }
    return originalWindowOpen.call(this, url, target, features);
};

// Parent receives message and navigates iframe
window.addEventListener('message', (event) => {
    if (event.data?.type === 'navigate-iframe' && event.data.url) {
        iframe.src = sw.encodeURL(event.data.url);
    }
});

Also intercepts click events on links with target="_blank", _new, _parent, _top and sets <base target="_self"> to prevent default new window behavior.

Preserves iframe capabilities: Does not modify iframe element attributes (required for UV/Scramjet functionality).

Screenshot

Homepage with proxy iframe

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: node server/index.js (dns block)
  • telemetry.astro.build
    • Triggering command: node /home/REDACTED/work/Radius/Radius/node_modules/.bin/astro build (dns block)
  • www.google.com
    • Triggering command: node server/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

make it so all urls will open inside the main site iframe and not in a new tab (be shure not to remove the widow open atrabut from the iframe, as then ultravilot will break. also be shure to make it so uv and scramjet are forced to open the new tab/window inside of the iframe for the proxyied content.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Nov 18, 2025
@codesandbox
Copy link

codesandbox bot commented Nov 18, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copilot AI and others added 3 commits November 18, 2025 22:46
…frame

Co-authored-by: sriail <225764385+sriail@users.noreply.github.com>
…pen interception

Co-authored-by: sriail <225764385+sriail@users.noreply.github.com>
Copilot AI changed the title [WIP] Update URL opening behavior to use main site iframe Force URLs to open in main iframe instead of new tabs Nov 18, 2025
Copilot AI requested a review from sriail November 18, 2025 23:00
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

Successfully merging this pull request may close these issues.

2 participants