franzenzenhofer / f19n-obtrusive-livetest

A sandboxed, extendable testing chrome extension and framework! It runs pre-defined and custom tests on each page that you visit.
https://chrome.google.com/webstore/detail/f19n-obstrusive-live-test/jbnaibigcohjfefpfocphcjeliohhold?hl=en
55 stars 1 forks source link

access to chrome.extension.getURL('codeview.html') in RuleContext.js #74

Closed franzenzenhofer closed 7 years ago

franzenzenhofer commented 7 years ago

hi @neuling some help please

I need access to the value of

chrome.extension.getURL('codeview.html')

in the

RuleContext.js

as due to security restrictions of data-URLs and blob URLs i need to run my own code viewer (which I will code in codeview.html). for this I need to be able to link to (the value of) chrome.extension.getURL('codeview.html') in RulesContext.js

(note: it's ok if this takes up to 1h) thx franz

neuling commented 7 years ago

@franzenzenhofer can you give me some additional information of what you are trying to achieve?

i am asking because there a different ways of communicate between files/scripts that run under the extension context.

for example because we need to run users custom rules, we need to execute 'eval' which is not allowed within the extension context. thats why i created a proxy page that runs 'sandbox' and communicates with the core part via postMessage.

i don't wanna waste time implementing the wrong behaviour.

franzenzenhofer commented 7 years ago

hi, what i want to achieve

image

i have this code preview functionality behind

</>

this is currently implemented as a blob link

https://github.com/franzenzenhofer/f19n-obtrusive-livetest/blob/0fc136c37abc899409ca93ac764ab7c100e9224c/src/javascripts/utils/RuleContext.js#L57

issue is, due to chrome security restrictions, you have to

right click it -> open in new tab

image

so that you can actually access the content of this link so a normal click or even a shift click will not work this seems to be some security restrictions of chrome

there are other restrictions (chrome cleans up the blob URLs if not accessed and this means that if you do not visit the blob url for some time, then click it later, the contents is gone)

previously I had implemented it as ad data:text/html link https://github.com/franzenzenhofer/f19n-obtrusive-livetest/blob/0fc136c37abc899409ca93ac764ab7c100e9224c/src/javascripts/utils/RuleContext.js#L49

but google changed the security restrictions on that one, too. if you clicked it the link opened, but it did not show any content, you had to click into the address bar and then hit enter to see the content.

so both of them are no longer viable options

so i now want to run my own codeview tool

codeview.html will just be a static html file with some JS

so if accessed codeview.html?show=sfhsdfkh

will just display the value of show as plain text (like the similar behaviour with the blob URL)

image

but for this to work I need to be able to link to codeview.html and for this I need the value of chrome.extension.getURL('codeview.html') in the rulecontext (or some method to access it) where I code the special util function to make the rule results more accessable

I do not need access to chrome.extension.getURL('codeview.html') but I do need access to the value of it.

is there a way to get this value, otherwise I would need to run an external website with this codeview functionality, but well I would rather not put an external dependency on the extension to work.

neuling commented 7 years ago

@franzenzenhofer got it + implemented!

you can now set globals that will be accessible from inside RuleContext via globals.KEY. details see commit. keep in mind that you can only pass an object that does not contain any functions because it needs to be serialized and passed via sendMessage to the sandbox.

neuling commented 7 years ago

@franzenzenhofer https://github.com/franzenzenhofer/f19n-obtrusive-livetest/blob/9cfd218c1755bc2fa80129ab85246205412237af/src/javascripts/utils/RuleContext.js#L70

replace this.codeviewUrl with globals.codeviewUrl.