Skip to content

Commit

Permalink
Merge pull request #7942 from cernbox/up_unsupported_browser
Browse files Browse the repository at this point in the history
[full-ci] Warn when using incompatible browser
  • Loading branch information
kulmann authored Dec 2, 2022
2 parents 8a31a5c + 4673c61 commit f964df4
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 27 deletions.
8 changes: 8 additions & 0 deletions changelog/unreleased/enhancement-warn-unsuported-browsers
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Enhancement: Warn users when using unsupported browsers

We've added a warning message if the browser is older than our supported configuration, instead of just failing and showing blue/white screens or generic errors.
Users still have the option to proceed and open the page if they want to. By proceeding to the page, the setting is set for 30 days, afterwards the warning is shown again.

When building web, it's possible to pass a documentation url for users to know more about this issue, by setting the env variable DOCUMENTATION_URL.

https://github.com/owncloud/web/pull/7942
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"autoprefixer": "10.4.13",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "29.3.1",
"browserslist-useragent-regexp": "^3.0.2",
"commander": "8.3.0",
"core-js": "3.26.1",
"cucumber-html-reporter": "5.5.0",
Expand Down
102 changes: 79 additions & 23 deletions packages/web-container/index.html.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@
}
.splash-banner {
display: flex;
flex-direction: row;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 0.5rem;
height: 100%;
}
#splash-loading{
height: 100%;
}
.splash-loading-hide {
.splash-hide {
display: none;
}
#loading {
Expand All @@ -44,6 +41,9 @@
animation: spin 1s ease-in-out infinite;
-webkit-animation: spin 1s linear infinite;
}
#splash-incompatible button {
margin: 30px 0;
}
@keyframes spin {
to { -webkit-transform: rotate(360deg); }
Expand All @@ -54,7 +54,34 @@
</style>
</head>
<body>
<div id="splash-loading" class="splash-banner splash-loading-hide">
<div id="splash-incompatible" class="splash-banner splash-hide">
<div class="oc-card oc-border oc-rounded oc-width-large oc-text-center">
<div class="oc-card-header">
<div class="oc-flex oc-flex-middle oc-flex-center">
<span class="oc-mr-s oc-icon oc-icon-m oc-icon-warning">
<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false">
<g xmlns="http://www.w3.org/2000/svg">
<path fill="none" d="M0 0h24v24H0z"></path>
<path d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm0-2a8 8 0 1 0 0-16 8 8 0 0 0 0 16zM11 7h2v2h-2V7zm0 4h2v6h-2v-6z"></path>
</g>
</svg>
</span>
<h2>Your browser is not supported</h2>
</div>
</div>
<div class="oc-card-body oc-link-resolve-error-message">
<p>Your browser version is considered old and might not work correctly.</p>
<p>We recommend you update to a newer version.</p>
</div>
</div>
<button class='oc-button oc-button-primary oc-button-primary-filled oc-rounded' onclick='forceOldBrowser()'>I want to continue anyway</button>
<% if (data.config.documentation_url) { %>
<p>
<a href='<%= data.config.documentation_url %>' target='_blank'>Click here to know more</a>
</p>
<% } %>
</div>
<div id="splash-loading" class="splash-banner splash-hide">
<div id="loading"></div>
</div>
<div id="owncloud"></div>
Expand All @@ -63,32 +90,61 @@
</noscript>
<script>
var loader = document.getElementById('splash-loading')
var browserError = document.getElementById('splash-incompatible')
var loaderTimer = setTimeout(function () {
loader.classList.remove('splash-loading-hide')
loader.classList.remove('splash-hide')
}, 1000);
function displayError() {
loader.classList.remove('splash-loading-hide')
loader.classList.remove('splash-hide')
loader.innerHTML = "<h3>Oops. Something went wrong.</h3>"
}
if (typeof requirejs === 'undefined') {
displayError()
} else {
requirejs.config({
baseUrl: <%- JSON.stringify(data.roots.js) %>,
paths: <%- JSON.stringify(data.bundle.js) %>,
...<%- JSON.stringify(data.config.requirejs) %>
})
function displayBrowserError() {
clearTimeout(loaderTimer)
loader.classList.add('splash-hide')
browserError.classList.remove('splash-hide')
}
requirejs(['web-runtime'], function (runtime) {
clearTimeout(loaderTimer)
document.getElementById('splash-loading').classList.add('splash-loading-hide')
runtime.bootstrap('config.json').then(runtime.renderSuccess).catch(runtime.renderFailure)
}, function(e) {
function forceOldBrowser() {
localStorage.setItem("forceAllowOldBrowser", JSON.stringify({expiry: new Date().getTime() + 30*24*60*60*1000}))
browserError.classList.add('splash-hide')
init()
}
function init() {
if (typeof requirejs === 'undefined') {
displayError()
throw e
})
} else {
requirejs.config({
baseUrl: <%- JSON.stringify(data.roots.js) %>,
paths: <%- JSON.stringify(data.bundle.js) %>,
...<%- JSON.stringify(data.config.requirejs) %>
})
requirejs(['web-runtime'], function (runtime) {
clearTimeout(loaderTimer)
document.getElementById('splash-loading').classList.add('splash-hide')
runtime.bootstrap('config.json').then(runtime.renderSuccess).catch(runtime.renderFailure)
}, function(e) {
displayError()
throw e
})
}
}
const supportedBrowsers = <%= data.supportedBrowsersRegex %>
const forceAllowOldBrowser = localStorage.getItem("forceAllowOldBrowser") || false
const validForceAllowOldBrowser = forceAllowOldBrowser && JSON.parse(localStorage.getItem("forceAllowOldBrowser")).expiry > new Date().getTime()
if (forceAllowOldBrowser && !validForceAllowOldBrowser)
localStorage.removeItem("forceAllowOldBrowser")
if (!validForceAllowOldBrowser && !supportedBrowsers.test(navigator.userAgent)) {
displayBrowserError()
} else {
init()
}
</script>
Expand Down
60 changes: 60 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@ import copy from '@rollup-extras/plugin-copy'
import packageJson from './package.json' assert { type: "json" }
import {fileURLToPath} from 'url'
import { dirname, resolve as pathResolve } from 'path'
import { getUserAgentRegExp } from 'browserslist-useragent-regexp'


const production = !process.env.ROLLUP_WATCH
const sourcemap = process.env.SOURCE_MAP === 'true'

const { version } = packageJson
const compilationTimestamp = new Date().getTime()
const supportedBrowsersRegex = getUserAgentRegExp({allowHigherVersions: true})

const config = {
requirejs: {},
cdn: process.env.CDN === 'true'
cdn: process.env.CDN === 'true',
documentation_url: process.env.DOCUMENTATION_URL
}
if (process.env.REQUIRE_TIMEOUT) {
config.requirejs.waitSeconds = parseInt(process.env.REQUIRE_TIMEOUT)
Expand Down Expand Up @@ -183,7 +186,8 @@ const plugins = [
js: 'js'
},
config: config,
compilationTimestamp: compilationTimestamp
compilationTimestamp: compilationTimestamp,
supportedBrowsersRegex: supportedBrowsersRegex
}
},
{},
Expand Down
5 changes: 3 additions & 2 deletions tests/acceptance/pageObjects/publicLinkPasswordPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ module.exports = {
selector: '.oc-login-authorize-button'
},
resourceProtectedText: {
selector: '//*[@class="oc-card-header"]',
selector: '//*[contains(@class, "oc-link-resolve")]//*[@class="oc-card-header"]',
locateStrategy: 'xpath'
},
linkResolveErrorTitle: {
selector: '.oc-link-resolve-error-title'
},
publicLinkPasswordSection: {
selector: '//*[@class="oc-card-header"]//*[text()="This resource is password-protected"]',
selector:
'//*[contains(@class, "oc-link-resolve")]//*[@class="oc-card-header"]//*[text()="This resource is password-protected"]',
locateStrategy: 'xpath'
}
}
Expand Down

0 comments on commit f964df4

Please sign in to comment.