Closed Bug 1200146 Opened 9 years ago Closed 8 years ago

Injecting Functions from Content Scripts - Show "sourceless code"

Categories

(WebExtensions :: Developer Tools, defect, P5)

42 Branch
defect

Tracking

(Not tracked)

RESOLVED WORKSFORME

People

(Reporter: ido.y, Unassigned)

References

Details

(Whiteboard: triaged)

Attachments

(1 file)

687 bytes, application/zip
Details
User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36

Steps to reproduce:

we used a content script to inject script to the page

the function for injecting the script is
	function appendContentScript(id, content) {
		var scriptTag = document.createElement('script');
		scriptTag.id = id;
		scriptTag.type = 'text/javascript';
		scriptTag.appendChild( document.createTextNode(content) );
		head.appendChild(scriptTag);
	}


Actual results:

when we try to parse a function as content for example
function test() {
alert('hi, im test!');
}
we get the following script
<script type="text/javascript" id="SCRIPT_ID">function test() { [sourceless code] }</script>


Expected results:

<script type="text/javascript" id="SCRIPT_ID">function test() { alert('hi, im test!'); }</script>
Component: Untriaged → Web Apps
OS: Unspecified → All
Hardware: Unspecified → All
Component: Web Apps → WebExtensions
Product: Firefox → Toolkit
Blocks: webext
Priority: -- → P4
Can you please attach a testcase add-on?
Attached file Extension.xpi
attached xpi
That add-on seems to work as expected for me.

In any case, I'd suggest converting the function to a string before passing it to createTextNode. And if you're using functions to inject code into pages like this, it would probably be best to always do something like `"(" + func + ")()"` rather than just injecting the bare function as a top-level function statement.
when "running" the code in the console it seems to work fine (without converting the function)
should it be different ?

about the self execution - it was just an example :)
Flags: blocking-webextensions+
Whiteboard: triaged
Flags: blocking-webextensions+ → blocking-webextensions-
Component: WebExtensions: Untriaged → WebExtensions: Developer tools
Flags: blocking-webextensions-
Priority: P4 → P5
Status: UNCONFIRMED → RESOLVED
Closed: 8 years ago
Resolution: --- → WORKSFORME
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: