Chrome extensions: How can I pass form variables to a url in a newly created tab? - xmlhttprequest

I'm working on my first chrome extension, and using an image-based context menu item to capture the URL of a given image, and want to then display that image at a specific URL in a new tab. So, I need to pass the URL of the image clicked on (using srcUrl) to a specific script that can then render it on that page. Is it possible to perform an HMLHttpRequest from within a chrome.tabs.create() call, or must this be done some other way?
Thanks for any help.

You would need to create an HTML page containing that script and put it into your extension folder. Then you can just pass image url to it as GET parameter:
chrome.tabs.create({url: "local.html?img_url=...");
If url parameter is not enough, you would be also able to communicate with that page using chrome.tabs.sendRequest():
chrome.tabs.create({url: "local.html", function(tab){
chrome.tabs.sendRequest(tab.id, {img_url: "local.html?img_url=...");
));
With the request listener in that page:
chrome.extension.onRequest.addListener(function(request) {
console.log(request.img_url);
});

Related

Customizing image uploading in TinyMCE

I have an ASP.NET Web API web service which I want to use for file uploading. The way I do this is that the client posts a JSON object to the service at http://myserver.com/api/images/upload .
The object would contain a base64 string representation of the image, plus some metadata, e.g:
{ companyId: 12345, image: "someBase64encodedStringRepresentingTheImage" }
I would like to use TinyMCE on the client side, but I can't figure out how to customize it such that images are uploaded to the server in that format. (Actually, it doesn't seem like TinyMCE comes with an image uploader at all)
TinyMCE 4.2+ actually has its own built in process for handling the upload of images that you place in the editor:
https://www.tinymce.com/docs/advanced/handle-async-image-uploads/
The basic process is that TinyMCE will create a separate HTTP POST for each image that you insert into the editor. It will send that image to a URL of your choosing (via HTTP POST) based on the setting of the images_upload_url option in your init.
The image handler at the URL referenced in the images_upload_url (which you have to create) has to do whatever needs to be done to "store" the image in your application. That could mean something like:
Store the item in a folder on your web server
Store the item in a database
Store the item in an asset management system
...regardless of where you choose to store the image your image handler needs to return a single line of JSON telling TinyMCE the new location of the image. As referenced in the TinyMCE documentation this might look like:
{ location : '/uploaded/image/path/image.png' }
TinyMCE will then update the image's src attribute to the value you return. If you use the images_upload_base_path setting in the init that will be prepended to the returned location.
The net here is that TinyMCE knows when an embedded image exists in your content but it can't possibly know what to do with that image in the context of your application so that job (the "image handler") is something you must create.
There is an option for you to write your own image handler if the default one is not sufficient:
https://www.tinymce.com/docs/configure/file-image-upload/#images_upload_handler
I would recommend trying to use the uploader that comes with TinyMCE so you don't have to write and maintain your own code going forward (always easier) but if the built in code is not appropriate you can indeed replace it with your own function.

PhantomJS AWS Browser Tab Title

I have a problem with my browser tab title.
Actually on my website I generate some report using PhantomJS and pull them on a AWS S3 Bucket. I access to them using some link like that : http://192.168.33.120/report/8/1?export=inline
The problem is that my Browser tab titles are like : 1 or 1?export=inline, it display the url and not my PDF file name.
Is that possible using PhantomJS to set a property like title or other think like that to specify the title that I want to show on browser view ?
The title of the rendered PDF cannot be explicitly set. document.title is also not used for the PDF title. Although, qpdfwriter.h has a setTitle function. You can issue a feature-request on GitHub to expose this function if you like.
You can also simply name your reports appropriately by selecting good URLs. That way the PDF title will be a non-issue.

CRM 2013 WebResource IFrame

I have an HTML web resource in an opportunity that produces a css tab control containing all children opportunity to the current record.
I do this through Ajax and javascript and everything works fine, a new tab is made for each child and it shows an opportunity record inside; the only issue is that it will only show the current record inside of this tab - effectively creating an endless loop.
If I paste the URL from the IFrame into the browser it shows the proper record using the right form that I specify(one that doesn't contain another web resource).
Does anyone know why it wouldn't show the same form as it navigates to? If I try google.com it works, just not for this URL:
http://server/CRM/main.aspx?etn=opportunity&pagetype=entityrecord&navbar=off&id=%7B"+val.OpportunityId+"%7D&extraqs=formid%3DC1EC704C-D29B-4786-806F-195D0A80CF07%0D%0A#255409204
Try constructing the URL with this format:
http://server/CRM/main.aspx?etc=3&extraqs=formid%3dC1EC704C-D29B-4786-806F-195Dā€Œā€‹0A80CF07%7d&id=%7b<EnterOppIdHere>%7d&pagetype=entityrecord
Use the Entity Type Code (etc parameter) instead of the Name (etn) and note that everything after that should be part of the extraqs parameter.

how to prevent changed url in the browser bar from reflecting in the website content?

how to prevent the change in the url of the browser bar from reflecting in the website content's URLS...
here is the situation,
in my current web app, I am using this
$this->createUrl(Yii::app()->controller->id ."/". Yii::app()->controller->action->id, $params)
to generate href of the hyperlinks... now the problem is,
when I type in the browser bar like e.g
www.mysite.com/blahblahblah/subcategory/c1
the blahblahblah, also reflects to the webpage content hyperlinks,because of the Yii::app()->controller->id that I passed to the createUrl function...any work around for this ?..., what i want to happen is, no matter what string is typed in the place of the controller name via the browser bar, it won't reflect in the webpage content hyperlinks ..
so how ?
the answer was, I took the ID from the URL ,created a simple Helper function and used that to return the correct value of category/subcategory and outputs it in the view source no matter what change is done via the browser bar

Open graph: custom actions

I created a custom action and object.
The only problem I have is when publishing to FB, clicking on the icon or on the title redirect the user to a blank page instead of my application.
Where can I set the redirect link?
The only url I see is the one in the opengrap html but this one is suppose to be the adress of the og wright? (
This link might help.
Basically, when the opengraph action is executed by your app, it sets the url that represents the object (which provides all the metadata for the object) and is also the URL that a user is sent to when they click the action in facebook.
E.g. https://graph.facebook.com/me/[YOUR_APP_NAMESPACE]:cook
?recipe=OBJECT_URL&access_token=ACCESS_TOKEN
In this case, the cook action is being called, with a recipe object with the given OBJECT_URL. At that url, a page should exists (generated by you), with all the facebook metadata in the head tag so that the object can be correctly created, but also with actual web page data for the user to view.
Another link worth looking at for a working example is here