accessing extension stylesheets via extension javascript - google-chrome-extension

I have a chrome content script extension that includes a css file (mystyle.css) which is bundled into the extenstion CRX. As far as I can tell, there are two ways to inject this this stylesheet into the content of a page.
No matter which way the stylesheet is injected into the page, I cannot access the CSS rules associated with that stylesheet.
Injection method #1:
// From a script running in the context of background.html:
chrome.tabs.insertCSS(tab.id, {file: 'mystyle.css'});
Injection method #2:
// From a script running in the context of the content, already
// injected by the background page via chrome.tabs.executeScript.
var fileref = document.createElement("link");
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href",
chrome.extension.getURL('mystyle.css'));
From JavaScript running in the context of the content, injected by the background page, I cannot see the stylesheet in the list of those listed in document.styleSheets, when it is injected using method #1. When injected using method #2, it is listed with a chrome-extension:// href, but the cssRules property of that the sheet is always null.
I would expect this for CSS sheets that are linked to the document from other domains, but my script should have access to chrome-extension:// URIs that pertain to my extension.
The avenue that I'm currently investigating is raw string access to the resource contents of the CSS file that I can construct a chrome-extension:// URI for. I have no idea if this will work better than the other attempts, but it seems like it should.

Related

Safari App Extensions: Can the injected script load resources from the app bundle?

I have a Safari App Extension that injects a script into the host page. From that injected script, is it possible to load resources such as images or stylesheets from the main app bundle? (I mean directly, without sending messages between the two.)
I suppose yes. In your injected script, the path to an asset called "gigou.css" located in your extension's bundle should be accessible with safari.extension.baseURI + 'gigou.css'. Then you should be able to write dynamically a link or script tag and inject it into the document.

Unable to replace Alert in injected script

I'm writing an extension for this site. In my injected script(injected using chrome.tabs.executeScript) which runs at "document_end" everything seems to be working fine but I want to remove site's "alert" prompts.
To do I've placed this code in the injected script but it does not work:
window.alert = function(msg){
console.log("bypassed");
}
Also tried this from the injected script:
$('<script>window.alert = function (msg){}</' + 'script>').appendTo(document.body);
I've even tried this in the background page but this too doesn't:
chrome.tabs.executeScript({
code: 'window.alert=function(msg){}' //while alert("hello") works
});
What am I missing? I've written another extension for another site and this method does override the alert function.
UPDATE: I'm unable to call native functions in the downloaded web page from the injected script which will happen when called from content script. But my injected script is loaded using chrome.tabs.executeScript
I am guessing that your issue is with your manifest.json file, where you have specified to "run_at": "document_end".
From the documentation:
In the case of "document_start", the files are injected after any files from css, but before any other DOM is constructed or any other script is run.
but,
In the case of "document_end", the files are injected immediately after the DOM is complete, but before subresources like images and frames have loaded.
Referencing this answer, in the case of document_end, the overwrite cannot take place as the functions are already loaded, therefore you should have the javascript be injected at document_start.

Custom Route for ServiceStack Razor Content Pages

I have the following content page: /folder/_new.cshtml
My intention is to have the page accessible through the following url: /folder/_new
However it seems that such file name is not mapped to the url. Is there any workaround to make it happen, perhaps by assigning a custom route instead of relying on the pretty-url-by-default feature?
This is a pre-defined restriction for not allowing views starting with a _ prefix to be called directly, the restriction can be removed when you're registering the ServiceStack.Razor plugin with:
var razor = new RazorFormat();
razor.Deny.RemoveAt(0);
Plugins.Add(razor);

Use local resources in WKWebview

How do I make WKWebview use local .js, .css and/or local image files, in place of remote files, in order to make the web page load faster.
Also, I noticed NSURLProtocol methods (when implemented through register class) do not get called when WKNavigationDelegate methods are implemented, any idea on why?
In iOS 9 API there is a new method for loading local resource
/*! #abstract Navigates to the requested file URL on the filesystem.
#param URL The file URL to which to navigate.
#param readAccessURL The URL to allow read access to.
#discussion If readAccessURL references a single file, only that file may be loaded by WebKit.
If readAccessURL references a directory, files inside that file may be loaded by WebKit.
#result A new navigation for the given file URL.
*/
#available(iOS 9.0, *)
func loadFileURL(URL: NSURL, allowingReadAccessToURL readAccessURL: NSURL) -> WKNavigation?
After going through a lot of documentation, I realized/learnt that I'll not be able to track URLs if I use WKWebviews. I have to resort to UIWebView for the moment.

TYPO3: extension with both backend module and frontend plugin

I am trying to create an extension ('XML Uploader') with a backend module and a frontend plugin also.
The backend module will be used for managing xml files (upload, validate against a DTD), and the frontend plugin should be used for displaying the uploaded xmls.
The problem is with the frontend part:
I followed
the basic extension tutorial - added a new page, created a content element of type 'Insert plugin' - but when trying to add a new record, the type 'XML Uploader' does not appear in the list of new record types. Moreover, the changes made to class.tx_xmluploader_pi1.php have no effect.
So how should I work with the frontend plugin? Or would it be better to create a separate extension instead?
Any help would be very much appreciated.. Thank you.
When creating your table with the extension kickstarter you must check the "Allowed on pages:" checkbox to allow records from this table to be created on regular pages.
If your changes have no effect, it could be that the page is cached by typo3. In that case you can clear or disable the cache with the admin panel or in the page configuration menu.
You have to include the static template of your extension (I presume you used the kickstarter or extension_builder):
go to the your template, in the object browser you should see something like:
plugin.tx_xmluploader_pi1 = USER
if you can't find it, edit your template (edit/modify => edit whole template record) and add your extension template in the tab 'Includes'
Additionally, check your ext_localconf.php for the line
t3lib_extMgm::addPItoST43($_EXTKEY, 'pi1/class.tx_xmluploader_pi1.php', '_pi1', 'list_type', 0);
This is where your FE plugin is being registered.

Resources