Python Selenium ChromeDriver change default margins: to none - selenium-webdriver

Under More settings, chrome (v96) has an option for Margins, which I have selected as none. Here are our options currently for chrome:
Here are our options currently, which are set so that we can save PDFs locally with Selenium:
def make_options(output_dir):
state = {
"recentDestinations": [
{
"id": "Save as PDF",
"origin": "local",
"account": ""
}
],
"selectedDestinationId": "Save as PDF",
"version": 2
}
profile = {'printing.print_preview_sticky_settings.appState': json.dumps(state),
'savefile.default_directory': output_dir,
"download.default_directory": output_dir}
chrome_options = webdriver.ChromeOptions()
chrome_options.headless = False
chrome_options.add_experimental_option('prefs', profile)
chrome_options.add_argument('--kiosk-printing')
return chrome_options
I can see in the PDFs saved with Selenium that Margins is not set to None. Is it possible to update the code above for this? We need Margins: None in the chrome options, setting it in the CSS of the webpage we are saving as PDF does not resolve our issue.

You can set the margin type in the json construct, the option for no Margins is 1. see this link https://github.com/chromium/chromium/blob/eadef3f685cd9e96e94fcb9645b6838b6d0907a8/chrome/browser/resources/print_preview/data/margins.js
edit your code to include this new line:
def make_options(output_dir):
state = {
"recentDestinations": [
{
"id": "Save as PDF",
"origin": "local",
"account": ""
}
],
"selectedDestinationId": "Save as PDF",
"version": 2,
"marginsType": 1
}
profile = {'printing.print_preview_sticky_settings.appState': json.dumps(state),
'savefile.default_directory': output_dir,
"download.default_directory": output_dir}
chrome_options = webdriver.ChromeOptions()
chrome_options.headless = False
chrome_options.add_experimental_option('prefs', profile)
chrome_options.add_argument('--kiosk-printing')
return chrome_options

Related

React Insta stories play next set of stories on end of first set

I am using this package to display Instagram like stories: https://github.com/mohitk05/react-insta-stories.
I have a set of stories from different persons in this structure:
let people = [ {
"name": "Sumesh",
"stories": [
{
"url": "url of image",
"type": "image"
},
{
"url": "url of video",
"type": "video"
}
]
},
{......}
];
What I need is when first set of stories are completed (above eg:2), I need to load the next set of stories. I am setting current stories to a state "items", the using the prop "onAllStoriesEnd"
loads the next set of items in "items state". But this doesn't work as expected. Has anyone a work around for this.
<Stories stories={items} onAllStoriesEnd={setAllStoryEnd} />
If someone looking for same, I fixed this by adding a key prop to the Stories component.

Send Lexical data to a server and read it with a new lexical component

this is my first time asking a question with stackoverflow, but I'm stuck on this problem for too many days.
My question, how can I change the initialConfig.editorState to the stringifiedEditorState that I just save in my database?
So far, I'm using Lexical, a Facebook text editor with React/Next.js. I was able to create an editor and save it to my mongodb database as a JSON string.
{
"root": {
"children": [
{
"children": [
{ "detail": 0, "format": 1, "mode": "normal", "style": "", "text": "Test", "type": "text", "version": 1 }
],
"direction": "ltr",
"format": "",
"indent": 0,
"type": "paragraph",
"version": 1
}
],
"direction": "ltr",
"format": "",
"indent": 0,
"type": "root",
"version": 1
}
}
I want to be able to read the Json value that I save to my mongodb database with a new read only lexical editor.
function onChange(editorState: any) {
editorState.read(() => {
const stringifiedEditorState = JSON.stringify(editorState.toJSON());
setValue(stringifiedEditorState);
});
}
const initialConfig = {
namespace: "editeurConfig",
theme: editeurTheme,
onError: onError,
nodes: [ListNode, ListItemNode, AutoLinkNode, LinkNode],
readOnly: true,
editorState: null
};
My question again, how can I change the initialConfig.editorState to the stringifiedEditorState that I just save in my database?
On editor initialization
You can simply pass the serialized string into the initial state of the editor via the editorState key.
For example:
// your config
const editorConfig = {
// the rest of your config...
editorState: editorStateJSONString,
};
// inside your return statement
<LexicalComposer initialConfig={editorConfig}>
{/* Your plugins */}
</LexicalComposer>
The caveat is that:
Note that Lexical uses initialConfig.editorState only once (when it's
being initialized) and passing different value later won't be
reflected in editor
From: https://lexical.dev/docs/concepts/editor-state
So it depends on the timing of initializing the editor and when you retrieve the database data.
After editor initialization
It appears you can use setEditorState to update state after initialization:
Another way to set state is setEditorState method, which replaces
current state with the one passed as an argument.
For example:
const editorState = editor.parseEditorState(editorStateJSONString);
editor.setEditorState(editorState);
From: https://lexical.dev/docs/concepts/editor-state#updating-state
For more details see: https://lexical.dev/docs/concepts/editor-state

Firefox add-on host permission error on tab with PDF file

I couldn't find this exact situation elsewhere: I have a custom add-on, which I'm loading temporarily via the developer menu. In the manifest file, I'm asking for a lot of permissions already:
{
"manifest_version": 2,
"name": "...",
"version": "1.0",
"description": "...",
"homepage_url": "...",
"permissions": [
"file:///*",
"*://*/*",
"<all_urls>",
"activeTab",
"bookmarks",
"contextMenus",
"tabs"
],
"background": {
"scripts": ["background.js"]
},
"browser_action": {
"default_icon": {
"19": "icon.svg"
},
"default_title": "..."
}
}
I have a background script only at the moment, however a small content script snippet gets injected:
(function() {
browser.browserAction.onClicked.addListener(async (tab) => {
let executing = browser.tabs.executeScript(tab.id, {
code: "window.getSelection().toString()"
})
...
try {
let selection = await executing
...
} catch(exception) {
console.log(exception)
}
...
})
})()
The purpose is essentially to get the current selection as text (for now) in order to later upload it to a bookmarking service of sorts.
However, when I have a tab open with a PDF file (https://www.example.com/file.pdf or file:///home/foo/file.pdf), the call of the content script to window.getSelection().toString() fails, with the following error:
Error: Missing host permission for the tab
Is this expected and I'm just missing a particular permission (and which one would that be)? Or is it unexpected and possibly worthy of a bug report?
Also, the call works in the developer console, which is why I'm thinking I'm really missing permissions somehow.

WebExtensions: browser.webRequest.onCompleted never fires

I'm using the Firefox WebExtensions API with the following background script
var log = console.log.bind(console)
log('hello world from browser extension')
// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/webRequest/onCompleted
var filter = { urls: '<all_urls>' }
var extraInfoSpec = ['tlsInfo', 'responseHeaders']
browser.webRequest.onCompleted.addListener(function(details){
log(`Woo got a request, here's the details!`, details)
}, filter, extraInfoSpec)
log('Added listener')
After loading the script from about:debugging, I see the following output in DevTools:
hello world from browser extension
I do not see any output- there is no data from browser.webRequest.onCompleted.addListener and there is no 'Added listener' message.
How do I make browser.webRequest.onCompleted work?
For completeness, my manifest.json is below:
{
"manifest_version": 2,
"name": "Test extension",
"version": "1.0",
"description": "Test extension.",
"icons": {
"48": "icons/border-48.png"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content.js"]
}
],
"permissions": [
"webRequest",
"webRequestBlocking"
]
}
The webRequest API is only available to background scripts. You seem to using it inside a content script.
urls in var filter = { urls: '<all_urls>' } needs to be be an array ['<all_urls>'].
'tlsInfo' in extraInfoSpec doesn't exist, I don't know where it comes from.
You need to specify an additional <all_urls> permission in your manifest.
script.js
var filter = { urls: ['<all_urls>'] }
var extraInfoSpec = ['responseHeaders']
browser.webRequest.onCompleted.addListener(function(details){
console.log(`Woo got a request, here's the details!`, details)
}, filter, extraInfoSpec)
console.log('Added listener')
manifest.json
{
"manifest_version": 2,
"name": "Test extension",
"version": "1.0",
"description": "Test extension.",
"icons": {
"48": "icons/border-48.png"
},
"background": {
"scripts": ["script.js"]
},
"permissions": [
"webRequest",
"webRequestBlocking",
"<all_urls>"
]
}

URL path variables in Azure Logic App Custom Connectors

I'm trying to build a Logic Apps Custom Connector that can update a JIRA issue (a feature not currently available in the prebuilt connector).
Here is a cURL example from the JIRA documentation for this request
curl -D- -u fred:fred -X PUT --data {see below} -H "Content-Type: application/json" http://kelpie9:8081/rest/api/2/issue/QA-31
{
"fields": {
"assignee":{"name":"harry"}
}
}
The QA-31 value is the unique identifier that I want to make a variable. Using Postman I set that as an Environment variable and successfully ran the request. When I uploaded the Postman collection to my custom connector 'QA-31' value wasn't available as a path variable
Then I tried editing the custom connector directly. In the Import Sample menu I replaced 'QA-31' in the URL with '{issueKey}'. This created a path variable but it also prefixed the url with '/en-us/widgets/manage'; which I don't want
Here is a picture of the problem
So there are a couple questions here:
Why is my path variable in Postman not being picked up in the custom connector while other requests from that collection were working fine
Why is my URL being prefixed with '/en-us/widgets/manage' when add a path variable in the 'Import from Sample' menu
Thanks!
Inside the Logic Apps Custom Connector Editor you may define path variables by enclosing the variable inside brackets (e.g. https://api.library.com/[method}/). This can be done manually during the "Definition" step of creating/editing your custom connector. However, the drawback is that you must use the "Import from sample" feature which requires you to manually rewrite the particular request.
To answer your question we can define the path variables in PostMan and then run the V1 export.
You can define a path variable in a Postman request by prepending a ':' to the variable name like so, https://api.library.com/:method/. This will add the key (method) and the optional value to the request parameters field.
When you export as a Postman V1 collection the resulting JSON code looks like,
{
"id": "fc10d942-f460-4fbf-abb6-36943a112bf6",
"name": "Custom Method Demo",
"description": "",
"auth": null,
"events": null,
"variables": [],
"order": [
"becb5ff8-6d31-48ee-be3d-8c70777d60aa"
],
"folders_order": [],
"folders": [],
"requests": [
{
"id": "becb5ff8-6d31-48ee-be3d-8c70777d60aa",
"name": "Custom Request Method",
"url": "https://api.library.com/:method",
"description": "Use a path variable to define a custom method.",
"data": null,
"dataMode": "params",
"headerData": [],
"method": "GET",
"pathVariableData": [
{
"key": "method",
"value": ""
}
],
"queryParams": [],
"auth": {
"type": "noauth"
},
"events": [
{
"listen": "prerequest",
"script": {
"id": "b7b91243-0c58-4dc6-b3ee-4fb4ffc604db",
"type": "text/javascript",
"exec": [
""
]
}
}
],
"folder": null,
"headers": "",
"pathVariables": {
"method": ""
}
}
]}
Notice the "pathVariables" field which corresponds to our custom path variable.
Now we can import this into our Logic App and the path variable is properly interpreted as described in the first paragraph.
Hope that helps.

Resources