Webcompat: implement PresentationRequest shim #2121
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Asana Task/Github Issue: https://app.asana.com/1/137249556945/project/1201614831475344/task/1210044338857086?focus=true
Description
Make the Presentation API shim spec-shaped for feature-detection code by allowing PresentationRequest construction, exposing urls/onconnectionavailable, and returning NotSupportedError rejections for unsupported operations.
This PR implements a spec-shaped PresentationRequest shim to support feature-detection code on sites that check for the Presentation API. The shim allows construction of PresentationRequest objects, exposes required properties (urls, onconnectionavailable), and returns NotSupportedError rejections for unsupported operations.
Testing Steps
Test Cases
1. PresentationRequest Constructor
Test 1.1: Basic construction with a single URL string
Test 1.2: Construction with an array of URLs
Test 1.3: Construction with an iterable
Test 1.4: Invalid constructor arguments should throw TypeError
2. URLs Property
Test 2.1: URLs property returns a copy (immutable)
3. onconnectionavailable Property
Test 3.1: Property exists and is initially null
Test 3.2: Property can be set to a function
4. start() Method
Test 4.1: Returns a rejected Promise with NotSupportedError
5. reconnect() Method
Test 5.1: Returns a rejected Promise with NotSupportedError
6. getAvailability() Method
Test 6.1: Returns a rejected Promise with NotSupportedError
7. navigator.presentation Object
Test 7.1: Presentation object exists
Test 7.2: defaultRequest property getter/setter
Test 7.3: receiver property
8. EventTarget Inheritance
Test 8.1: PresentationRequest extends EventTarget
9. Feature Detection Compatibility
Test 9.1: Common feature detection patterns should work
10. Real-world Site Testing
Test on sites known to use the Presentation API for feature detection:
YouTube - Uses Presentation API for Cast functionality
Netflix - May check for Presentation API
Any site with Cast/Presentation features
Regression Testing
Ensure native Presentation API is not overwritten
window.navigator.presentation && window.PresentationRequestshould prevent shimIntegration test environment
this.injectName !== 'integration'check)Expected Behaviour Summary
Checklist
Please tick all that apply: