chrome extension how to inject js script throught “frameset” before it load











up vote
0
down vote

favorite












Maybe you can try it -- add chrome support for an old webpage game: mopet as a player.



It use scripts in HTML to create DOMs... and document.createElement('') causes bugs.
I have write a script to rewrite the function like it:



document.createElementNormal = document.createElement;
document._parser = new DOMParser();

document.createElement = function (obj) {
let str = obj.toString();
if (str[0] == '<') {
let pt = /(w+)=([w/.-_:]+?)([ >])/g;
str = str.replace(pt, '$1="$2"$3');
return document._parser.parseFromString(str, 'text/xml').children[0];
}
else if (str[0] == '[') {
return obj.cloneNode(true);
}
else
{
return document.createElementNormal(obj);
}
};


and try to inject into the page.



Using content script to add a "head" element failed(start at document_end), because its "frame" will load before the script worked.



Then I try to find the main script, save it as local file, add the function, and return it. But maybe this changes the script's path? The scripts that references this file report error.



Then I try to use "document.write" to rewrite the main page like this:



document.write(`
<head>
<script>
document.createElementNormal = document.createElement;
document._parser = new DOMParser();

document.createElement = function (obj) {
let str = obj.toString();
if (str[0] == '<') {
let pt = /(w+)=([w/.-_:]+?)([ >])/g;
str = str.replace(pt, '$1="$2"$3');
return document._parser.parseFromString(str, 'text/xml').children[0];
}
else if (str[0] == '[') {
return obj.cloneNode(true);
}
else
{
return document.createElementNormal(obj);
}
};
</script>
</head>
`);

document.write(`
<frameset rows="*,0" border="0" frameborder="0" framespacing="0" id="frameset_top" name="frameset_top">
<frame scrolling="yes" noresize src="loading.html" border="0" frameborder="0" framespacing="0"></frame>
<frame scrolling="auto" noresize src="#" border="0" frameborder="0" framespacing="0" name="frame_sound" id="frame_sound"></frame>
</frameset>
`);


And it still doesn't work in the frameset.



How can I inject it? Or I can only get almost all the resources I can get, and rewrite the frontend of this website?










share|improve this question






















  • If it's a Chrome Extension, there is an option in the manifest that lets you inject the JS before anything else happens. It's described here: stackoverflow.com/questions/19191679/…
    – Besto
    Nov 11 at 3:28















up vote
0
down vote

favorite












Maybe you can try it -- add chrome support for an old webpage game: mopet as a player.



It use scripts in HTML to create DOMs... and document.createElement('') causes bugs.
I have write a script to rewrite the function like it:



document.createElementNormal = document.createElement;
document._parser = new DOMParser();

document.createElement = function (obj) {
let str = obj.toString();
if (str[0] == '<') {
let pt = /(w+)=([w/.-_:]+?)([ >])/g;
str = str.replace(pt, '$1="$2"$3');
return document._parser.parseFromString(str, 'text/xml').children[0];
}
else if (str[0] == '[') {
return obj.cloneNode(true);
}
else
{
return document.createElementNormal(obj);
}
};


and try to inject into the page.



Using content script to add a "head" element failed(start at document_end), because its "frame" will load before the script worked.



Then I try to find the main script, save it as local file, add the function, and return it. But maybe this changes the script's path? The scripts that references this file report error.



Then I try to use "document.write" to rewrite the main page like this:



document.write(`
<head>
<script>
document.createElementNormal = document.createElement;
document._parser = new DOMParser();

document.createElement = function (obj) {
let str = obj.toString();
if (str[0] == '<') {
let pt = /(w+)=([w/.-_:]+?)([ >])/g;
str = str.replace(pt, '$1="$2"$3');
return document._parser.parseFromString(str, 'text/xml').children[0];
}
else if (str[0] == '[') {
return obj.cloneNode(true);
}
else
{
return document.createElementNormal(obj);
}
};
</script>
</head>
`);

document.write(`
<frameset rows="*,0" border="0" frameborder="0" framespacing="0" id="frameset_top" name="frameset_top">
<frame scrolling="yes" noresize src="loading.html" border="0" frameborder="0" framespacing="0"></frame>
<frame scrolling="auto" noresize src="#" border="0" frameborder="0" framespacing="0" name="frame_sound" id="frame_sound"></frame>
</frameset>
`);


And it still doesn't work in the frameset.



How can I inject it? Or I can only get almost all the resources I can get, and rewrite the frontend of this website?










share|improve this question






















  • If it's a Chrome Extension, there is an option in the manifest that lets you inject the JS before anything else happens. It's described here: stackoverflow.com/questions/19191679/…
    – Besto
    Nov 11 at 3:28













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Maybe you can try it -- add chrome support for an old webpage game: mopet as a player.



It use scripts in HTML to create DOMs... and document.createElement('') causes bugs.
I have write a script to rewrite the function like it:



document.createElementNormal = document.createElement;
document._parser = new DOMParser();

document.createElement = function (obj) {
let str = obj.toString();
if (str[0] == '<') {
let pt = /(w+)=([w/.-_:]+?)([ >])/g;
str = str.replace(pt, '$1="$2"$3');
return document._parser.parseFromString(str, 'text/xml').children[0];
}
else if (str[0] == '[') {
return obj.cloneNode(true);
}
else
{
return document.createElementNormal(obj);
}
};


and try to inject into the page.



Using content script to add a "head" element failed(start at document_end), because its "frame" will load before the script worked.



Then I try to find the main script, save it as local file, add the function, and return it. But maybe this changes the script's path? The scripts that references this file report error.



Then I try to use "document.write" to rewrite the main page like this:



document.write(`
<head>
<script>
document.createElementNormal = document.createElement;
document._parser = new DOMParser();

document.createElement = function (obj) {
let str = obj.toString();
if (str[0] == '<') {
let pt = /(w+)=([w/.-_:]+?)([ >])/g;
str = str.replace(pt, '$1="$2"$3');
return document._parser.parseFromString(str, 'text/xml').children[0];
}
else if (str[0] == '[') {
return obj.cloneNode(true);
}
else
{
return document.createElementNormal(obj);
}
};
</script>
</head>
`);

document.write(`
<frameset rows="*,0" border="0" frameborder="0" framespacing="0" id="frameset_top" name="frameset_top">
<frame scrolling="yes" noresize src="loading.html" border="0" frameborder="0" framespacing="0"></frame>
<frame scrolling="auto" noresize src="#" border="0" frameborder="0" framespacing="0" name="frame_sound" id="frame_sound"></frame>
</frameset>
`);


And it still doesn't work in the frameset.



How can I inject it? Or I can only get almost all the resources I can get, and rewrite the frontend of this website?










share|improve this question













Maybe you can try it -- add chrome support for an old webpage game: mopet as a player.



It use scripts in HTML to create DOMs... and document.createElement('') causes bugs.
I have write a script to rewrite the function like it:



document.createElementNormal = document.createElement;
document._parser = new DOMParser();

document.createElement = function (obj) {
let str = obj.toString();
if (str[0] == '<') {
let pt = /(w+)=([w/.-_:]+?)([ >])/g;
str = str.replace(pt, '$1="$2"$3');
return document._parser.parseFromString(str, 'text/xml').children[0];
}
else if (str[0] == '[') {
return obj.cloneNode(true);
}
else
{
return document.createElementNormal(obj);
}
};


and try to inject into the page.



Using content script to add a "head" element failed(start at document_end), because its "frame" will load before the script worked.



Then I try to find the main script, save it as local file, add the function, and return it. But maybe this changes the script's path? The scripts that references this file report error.



Then I try to use "document.write" to rewrite the main page like this:



document.write(`
<head>
<script>
document.createElementNormal = document.createElement;
document._parser = new DOMParser();

document.createElement = function (obj) {
let str = obj.toString();
if (str[0] == '<') {
let pt = /(w+)=([w/.-_:]+?)([ >])/g;
str = str.replace(pt, '$1="$2"$3');
return document._parser.parseFromString(str, 'text/xml').children[0];
}
else if (str[0] == '[') {
return obj.cloneNode(true);
}
else
{
return document.createElementNormal(obj);
}
};
</script>
</head>
`);

document.write(`
<frameset rows="*,0" border="0" frameborder="0" framespacing="0" id="frameset_top" name="frameset_top">
<frame scrolling="yes" noresize src="loading.html" border="0" frameborder="0" framespacing="0"></frame>
<frame scrolling="auto" noresize src="#" border="0" frameborder="0" framespacing="0" name="frame_sound" id="frame_sound"></frame>
</frameset>
`);


And it still doesn't work in the frameset.



How can I inject it? Or I can only get almost all the resources I can get, and rewrite the frontend of this website?







javascript google-chrome-extension






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 3:14









CC. Zhuo

1




1












  • If it's a Chrome Extension, there is an option in the manifest that lets you inject the JS before anything else happens. It's described here: stackoverflow.com/questions/19191679/…
    – Besto
    Nov 11 at 3:28


















  • If it's a Chrome Extension, there is an option in the manifest that lets you inject the JS before anything else happens. It's described here: stackoverflow.com/questions/19191679/…
    – Besto
    Nov 11 at 3:28
















If it's a Chrome Extension, there is an option in the manifest that lets you inject the JS before anything else happens. It's described here: stackoverflow.com/questions/19191679/…
– Besto
Nov 11 at 3:28




If it's a Chrome Extension, there is an option in the manifest that lets you inject the JS before anything else happens. It's described here: stackoverflow.com/questions/19191679/…
– Besto
Nov 11 at 3:28

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245541%2fchrome-extension-how-to-inject-js-script-throught-frameset-before-it-load%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245541%2fchrome-extension-how-to-inject-js-script-throught-frameset-before-it-load%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python