external icon indicating copy to clipboard operation
external copied to clipboard

Reinterpret nextcloud internal links

Open rgon opened this issue 3 years ago • 2 comments

ENHANCEMENT

It'd be nice if the app detected links to the same nextcloud instance: i.e. to a file or directory https://yourservercloud.tld/f/00000000 or to any other subdirectory (essentiallyNEXTCLOUDURL/.*) and redirected to them instead of embedding the result.

Actual behaviour

If an embedded website contains such a link and the user accesses it, there'll be a child Nextcloud GUI instance inside the parent Nextcloud instance, which is confusing, makes little sense and can be repeated indefinitely.

Expected behaviour

Any link inside the iframe which targets the current nextcloud instance causes the parent website to redirect to that URL.

Usage case in which

Embedding the URL of an app running on a subdomain which saves its files inside a nextcloud-shared directory and has a link to the share to find it easier. External, private apps which use nextcloud as a backend.

rgon avatar Dec 25 '21 21:12 rgon

Possible implementation

To commit injs/external.js. Works in the Developer Options console in Firefox 95. However, needs to wait for the page to load (usually not fast). Would be great if we could catch the unload iframe event (but we cannot bind to it because it'll initially be a cross-origin domain.

The value however does seem to change instantly, so a mutation observer may work? (alert(document.getElementById('ifm').contentWindow.location.href) works).

let ifr = document.getElementById('ifm');
ifr.onload = function () {
    try {
        let ifrLocation = ifr.contentWindow.location;
        if (ifrLocation.hostname.match(window.location.hostname)) {
            window.location.href = ifrLocation.href;
        }
    } catch (e) {
        // Ignore error: means the iframe is in another domain and CORS prohibits reading the URL
    }
};

rgon avatar Dec 25 '21 21:12 rgon

@rgon you can follow the suggestion here to remove the header for an external site: https://github.com/nextcloud/deck/issues/2840#issuecomment-903565288

meichthys avatar Oct 27 '22 13:10 meichthys