Commit c2fba761 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

Also overwrite document.createElement using exportFunction

Ensures it works in Firefox on sites with content security policy like Spotify.

Differential Revision: https://phabricator.kde.org/D25569
parent 8d1716f1
......@@ -814,27 +814,39 @@ function loadMediaSessionsShim() {
player.addEventListener("pause", player.replayAfterRemoval);
`;
executeScript(`function() {
var oldCreateElement = Document.prototype.createElement;
Document.prototype.createElement = function() {
var createdTag = oldCreateElement.apply(this, arguments);
var tagName = arguments[0];
if (typeof tagName === "string") {
if (tagName.toLowerCase() === "audio") {
const player = createdTag;
${addPlayerToDomEvadingAutoPlayBlocking}
} else if (tagName.toLowerCase() === "video") {
(document.head || document.documentElement).appendChild(createdTag);
createdTag.parentNode.removeChild(createdTag);
}
}
const handleCreateElement = `
const tagName = arguments[0];
return createdTag;
};
if (typeof tagName === "string") {
if (tagName.toLowerCase() === "audio") {
const player = createdTag;
${addPlayerToDomEvadingAutoPlayBlocking}
} else if (tagName.toLowerCase() === "video") {
(document.head || document.documentElement).appendChild(createdTag);
createdTag.parentNode.removeChild(createdTag);
}
}
`);
`;
if (IS_FIREFOX) {
const oldCreateElement = Document.prototype.createElement;
exportFunction(function() {
const createdTag = oldCreateElement.apply(this, arguments);
eval(handleCreateElement);
return createdTag;
}, Document.prototype, {defineAs: "createElement"});
} else {
executeScript(`
function() {
const oldCreateElement = Document.prototype.createElement;
Document.prototype.createElement = function() {
const createdTag = oldCreateElement.apply(this, arguments);
${handleCreateElement}
return createdTag;
};
}
`);
}
// We also briefly add items created as new Audio() to the DOM so we can control it
// similar to the document.createElement hack above since we cannot share variables
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment