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

added webCompat as a docs page #690

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
59 changes: 47 additions & 12 deletions src/features/web-compat.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import ContentFeature from '../content-feature.js'

/**
* Fixes incorrect sizing value for outerHeight and outerWidth
* @module Web Compat
*
* @description
*
* A suite of individual 'fixes'
*
* - {@link default.windowSizingFix Window Sizing Fix}
* - {@link default.navigatorCredentialsFix Navigator Credentials Fix}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda shame we need to do this, is there no other way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it's not the nicest, but it is checked at build time which makes it slightly better.

another way, would be to encapsulate each sub feature into it's own class/module - but I think that might be going further than you want (in terms of code change for docs).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or, we can omit the list - it was just a nice way to list them when you land on the top-level webCompat

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind, just don't really like having manual steps and loads of boilerplate to make docs happy. I'll let you make the judgement here, I agree splitting to separate classes seems a little overkill too, but I don't mind if there's other benefits.

* - {@link default.safariObjectFix Safari Object Fix}
* - {@link default.notificationFix Notification Fix}
* - {@link default.messageHandlersFix Message Handlers Fix}
* - {@link default.notificationFix Notification Fix}
* - {@link default.permissionsFix Permissions Fix}
*
*/
function windowSizingFix () {
if (window.outerHeight !== 0 && window.outerWidth !== 0) {
return
}
window.outerHeight = window.innerHeight
window.outerWidth = window.innerWidth
}

import ContentFeature from '../content-feature.js'

export default class WebCompat extends ContentFeature {
init () {
if (this.getFeatureSettingEnabled('windowSizing')) {
windowSizingFix()
this.windowSizingFix()
}
if (this.getFeatureSettingEnabled('navigatorCredentials')) {
this.navigatorCredentialsFix()
Expand All @@ -34,6 +40,17 @@ export default class WebCompat extends ContentFeature {
}
}

/**
* Fixes incorrect sizing value for outerHeight and outerWidth
*/
windowSizingFix () {
if (window.outerHeight !== 0 && window.outerWidth !== 0) {
return
}
window.outerHeight = window.innerHeight
window.outerWidth = window.innerWidth
}

/**
* Notification fix for adding missing API for Android WebView.
*/
Expand Down Expand Up @@ -186,9 +203,27 @@ export default class WebCompat extends ContentFeature {

/**
* Support for proxying `window.webkit.messageHandlers`
*
* This was added to fix breakage in situations where sites
* see `window.webkit` and then assume their own handlers would be present.
*
* For example, it fixes when a site tries to do the following:
*
* ```javascript
* if (window.webkit) {
* window.webkit.messageHandlers.myHandler.postMessage({})
* // ^^^^^^^^^ when this is absent, postMessage throws
* }
* ```
*
* **Remote Config:**
*
* This feature needs to be configured to allow some known
* methods (ones we add) to pass though (using Reflect) whilst polyfilling others,
* see {@link "Webcompat Settings Schema".WebCompatSettings.messageHandlers}
*/
messageHandlersFix () {
/** @type {import('../types//webcompat-settings').WebCompatSettings['messageHandlers']} */
/** @type {import('../types/webcompat-settings').WebCompatSettings['messageHandlers']} */
const settings = this.getFeatureSetting('messageHandlers')

// Do nothing if `messageHandlers` is absent
Expand Down
1 change: 1 addition & 0 deletions typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"src/features/duckplayer/thumbnails.js",
"src/features/duckplayer/video-overlay.js",
"src/features/harmful-apis.js",
"src/features/web-compat.js",
"packages/messaging",
"packages/messaging/schema.js",
"packages/messaging/native.js",
Expand Down
Loading