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?
javascript google-chrome-extension
add a comment |
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?
javascript google-chrome-extension
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
add a comment |
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?
javascript google-chrome-extension
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
javascript google-chrome-extension
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
add a comment |
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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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