Implements a strategy to bring back picture in picture support for YouTube videos. Picture in picture implementation is behind feature flag `kBravePictureInPictureForYouTubeVideos` enabled by default. Test coverage has been extensively discussed and introduced to make sure: - We don't have race conditions when injecting the JS script - We don't inject the script multiple times on same page navigation - We don't create side effects in case of unexpected changes, and/or serialzed flags don't match - We inject/modify the serialized flags in case of partial match --------- Co-authored-by: bridiver <34129+bridiver@users.noreply.github.com>
28 lines
713 B
HTML
28 lines
713 B
HTML
<html>
|
|
<head>
|
|
<title>OK</title>
|
|
<script>
|
|
// Backup the original `replace` method.
|
|
const originalReplace = String.prototype.replace;
|
|
|
|
// Add a counter to track the number of times `replace` is called.
|
|
let replaceCallCount = 0;
|
|
|
|
// Override `String.prototype.replace`.
|
|
String.prototype.replace = function (...args) {
|
|
// Increment the counter.
|
|
replaceCallCount++;
|
|
|
|
// Call the original `replace` method and return the result.
|
|
return originalReplace.apply(this, args);
|
|
};
|
|
|
|
// Function to get the current replace call count.
|
|
window.getReplaceCallCount = function () {
|
|
return replaceCallCount;
|
|
};
|
|
</script>
|
|
</head>
|
|
<body></body>
|
|
</html>
|