How to change preload in webview? - webview

When I first call webview.src="someurl" after that any changes of webview.preload="somescript" are not working, it will load script that was loaded before first src change.
I want to add different preload script depending on url.
How to fix this?
electron 20.1.1

Related

Xamarin WebView baseUrl not resolving images path when initiate from script or styles

I run in to issue with Xamarin IOS WebView and probably BaseUrl.
I already set BaseUrl for Android and IOS and when Images/Script/Styles are defined directly in loaded HTML everything works fine.
The real problem occurs when script/style try to load image or icon.
Instead of path: file://User/mac/Library/..../some_image.png, url shows: file://some_image.png
How to force Xamarin to load images from script (a React application compiled with webpack) also with proper URL?
Edit:
Here are my codes:
https://imgur.com/a/2dVqleO
As you see images directly in HTML are working ... Although images invoked from "script" or React View as == exactly as in HTML are not working.
I have a workaround loading this path to hidden field and then use it in script. But i thought there is more "elegant" way to do this.

vlc extension - load with each video and select subtitle

I made a vlc extension subtitles extension that autoloads the proper subtitle if available in the current folder. However, I can't implement the following:
I can't automatically run the extension on each video load. I can only run the extension manually (ie via function activate()). This may be a built in safety feature. If there isn't a way to automatically run on each video load, is there a way to assign the extension a hotkey?
After loading the subtitles, I can't have it automatically select it. I have to manually set it after its loaded. I am using the following to add subtitles with uriSub set as a file path to the subtitle:
vlc.var.set(vlc.object.input(), 'sub-file', uriSub)
vlc.input.add_subtitle(uriSub)
FYI, I am basing my code on existing extensions since I hadn't found documentation to base it off.
https://www.opencode.net/tristargod/vlcsubber
Update 1
I was able to resolve issue 2 by vlc.input.add_subtitle(uriSub, true)
Still need help with issue 1
For this issue, I wasn't able to fully resolve it. It might be a security pre-caution by vlc. However, I was able to make it run on each video after the initial activation.
vlc.input.add_subtitle(uriSub, true) resolved it

iOS - Download files to application folder

I do have a UIWebview inside one of my UIViewControllers. The destination URL to be displayed within the WebView is a page on my server (therefore I have access to make changes on it).
That page basically has a list of PDFs to be downloaded (imagine an un-ordered list of hyperlinks each pointing to a PDF file).
I need a way to tell my App that whenever a file is downloaded from that WebView by clicking on one of the links, I need it to be saved inside my application folder instead of the iPhone/iPad memory.
Is there any way I can achieve that? Are there alternatives?
You can allow UIWebView to call your Objective-C delegate function. This link provides an overview of how to do it: http://dblog.com.au/iphone-development/iphone-sdk-tip-firing-custom-events-when-a-link-is-clicked-in-a-uiwebview/ Basically, the delegate function will be called on all requests from the UIWebView. You can examine if they are for links to a pdf files, and if so, write your own objective-c code to download the file and store it in your Application directory. You'll probably want to add some UI to let the user know what is happening. Otherwise you let the request go on as normal and it will be displayed in the web browser.

Include library from data directory in main.js in Firefox add-on

In my Firefox add-on using the Add-on SDK, I'm trying to include two library files from the data directory in main.js, and it's not working.
I have the following directory structure:
data
-- jquery-latest.min.js
-- pagemodscript.js
-- mylibrary.js
lib
-- main.js
pagemodscript.js uses jQuery, and that works (using contentScriptFile).
I also want to use jQuery and mylibrary.js in main.js, but that's not working.
Various things I've tried result in error messages "ReferenceError: [class in mylibrary.js] is not defined", "ModuleNotFoundError: unable to satisfy: require(mylibrary.js)", and "has no authority to load".
I tried moving mylibrary.js and copying jquery-latest.min.js to lib, but that resulted in one of those error messages.
What's the best way to set this up?
Note: the reason I want to use jQuery in main.js is because - after an event generated by pagemodscript.js - I want main.js to add a div to the current page in which it will display a list of objects it created from another event generated by pagemodscript.js. Is the better practice to have pagemodscript.js create those objects and create the div? In that case, this would work: I'd load mylibrary.js into pagemodscript.js using contentScriptFile. In that case, pagemodscript.js would be creating objects of the class defined in mylibrary.js, and that doesn't seem as good a design as the way I'd prefer to do things.
I also want to use jQuery and mylibrary.js in main.js
That won't do you any good. jQuery expects to run in a window and works with the DOM. Extension files execute in an entirely different environment - there is no window to access and some typical window functions are unavailable. Also, extension files simply aren't allowed to access the DOM, all web page access has to happen in content scripts.
I want main.js to add a div to the current page
You should send a message to your content script (pagemodscript.js) and let it create the div for you. That's how it works with the Add-on SDK.

I cannot get the StageWebViewBridge to load external assets

I am using appfile:/. The path is correct; if I put it on screen and copy-paste it in the explorer it links to the image.
Is there anything else I need to do?
UPDATED I have updated the library, now is more easy to use. Can you test it?
I am the author of the StageWebViewBridge class. There is a known problem if you are using Android. Anyway, I have a working solution I will update the next week.
If the problem is not in Android, then send me some code.
I am also confused on how to access locally packaged assets. I put them in the HTML folder as requested and when I send a signal to the StageWebViewBridge to set the .src attribute of a video I'm not sure how to do it.
Without StageWebViewBridge and entirely in a website I can just reference the file for a video object via JavaScript directly e.g. swvRef.src = 'file.mp4';. This works perfectly fine. When I try to tell flash to send a call via StageWebViewBridge it does receive the call to the StageWebView (I have JavaScript reporting it). However when I try to set the .src of a video object I can't figure out the correct path.
The documentation says to put all things in a 'html' folder. I did so. No reference to a .src of 'html/a.mp4' or 'a.mp4' or 'htmlCache/a.mp4' ever makes the new javascript html5 video class work.
Bridge otherwise is working perfectly sending AS->JS and JS->AS. I'm just looking for info on how to reference packaged files. I want to play a video I put in the /html folder and so far, I just can't do it.
Got the same issue and fixed it with "appfile:/"
Why do you require "appfile:/ for a local html file ?
If the treated html/js/css is local and asset is relative (aka ../ or no http://) you should treat them as "appfile:/" ?
If the treated file is distant you do not have to handle assets ?
Is there a best practice to work with "appfile:/" ?
Actually I debug my html/js/css game in the browser but if I use appfile:/ it will no longer works. I will have to handle 2 behaviors.

Resources