Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/components/PluginLoader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ const injectHeaderbarHidingStyles = (event) => {
}
}

/**
* Set <base target="_blank" in the app doc,
* so target="_blank" is the default for links, and they open in new tabs
*/
const injectHtmlBaseTag = (event) => {
try {
const iframe = event?.target || document.querySelector('iframe')
const doc = iframe.contentDocument
const baseElement = doc.createElement('base')
baseElement.target = '_blank'
doc.head.appendChild(baseElement)
} catch (err) {
console.error(
'Failed to inject <base> element in client app.' +
'This could be due to the client app being hosted on a different domain.',
err
)
}
}

// todo: this is kinda duplicated between here and the header bar
const getPluginEntrypoint = (appName, modules) => {
// If core apps get a different naming scheme, this needs revisiting
Expand Down Expand Up @@ -186,6 +206,7 @@ export const PluginLoader = ({ appsInfoQuery }) => {
return
}
injectHeaderbarHidingStyles(event)
injectHtmlBaseTag(event)
watchForHashRouteChanges(event)
initClientOfflineInterface({
clientWindow: event.target.contentWindow,
Expand Down
Loading