Allow Flash content in Chrome 71 running via chromedriver - google-chrome

I've been using this to allow flash for chrome version 69.
ChromeOptions options = new ChromeOptions();
// disable ephemeral flash permissions flag
options.addArguments("--disable-features=EnableEphemeralFlashPermission");
Map<String, Object> prefs = new HashMap<>();
// Enable flash for all sites for Chrome 69
prefs.put("profile.content_settings.exceptions.plugins.*,*.setting", 1);
options.setExperimentalOption("prefs", prefs);
nestedDriver = new ChromeDriver(options);
Now on version 71 of chrome, this experimental feature (EphemeralFlashPermission) has been removed.
I've also tried to use these settings but it didn't work as well.
prefs.put("profile.default_content_setting_values.plugins", 1);
prefs.put("profile.content_settings.plugin_whitelist.adobe-flash-player", 1);
prefs.put("profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player", 1);
Is there any other way now to enable flash using chromedriver?

I haven't find any option yet, and I'm afraid won't find ever.
The workaround for Windows is to use Group Policies (via adding entries to registry):
reg add HKLM\Software\Policies\Google\Chrome /v DefaultPluginsSetting /d 1 /t REG_DWORD /f
reg add HKLM\Software\Policies\Google\Chrome\PluginsAllowedForUrls /v 1 /d http://* /t REG_SZ /f
reg add HKLM\Software\Policies\Google\Chrome\PluginsAllowedForUrls /v 2 /d https://* /t REG_SZ /f
or just create file with .reg extension and put text below into it:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google]
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome]
"DefaultPluginsSetting"=dword:00000001
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome\PluginsAllowedForUrls]
"1"="http://*"
"2"="https://*"
then save and double-click this file.

My little workaround about this, ty to #doctordrue ;)
from winreg import *
import sys
reg_path = 'Software\Policies\Google\Chrome\PluginsAllowedForUrls'
allow_flash = {'1': 'https://url'}
if sys.platform == 'win32':
try:
try:
RegistryKey = OpenKey(HKEY_LOCAL_MACHINE, reg_path, 0, KEY_ALL_ACCESS)
for K,V in allow_flash.items():
try:
if QueryValueEx(RegistryKey, K)[0] == V: pass
else:
SetValueEx(RegistryKey, K, 0, REG_SZ, V)
except FileNotFoundError:
SetValueEx(RegistryKey, K, 0, REG_SZ, V)
CloseKey(RegistryKey)
except FileNotFoundError:
RegistryKey = CreateKey(HKEY_LOCAL_MACHINE, reg_path)
for K, V in allow_flash.items():
SetValueEx(RegistryKey, K, 0, REG_SZ, V)
CloseKey(RegistryKey)
except:
# write_in_log(traceback.format_exc())
pass

Related

Chromium debug build no TCMalloc symbols

I compiled Chromium as debug build
# Set build arguments here. See `gn help buildargs`.
enable_nacl=false
symbol_level=2
is_asan = true
is_lsan = false
is_debug = true
but somehow I cannot see TCMalloc symbols when using TCMalloc inspection script:
https://github.com/marcinguy/tcmalloc-inspector
With sample program compiled against TCMalloc it works.
In Chromium it cannot find these symbols:
# tcmalloc
pageheap_ = gdb.parse_and_eval('\'tcmalloc::Static::pageheap_\'')
central_cache_ = gdb.parse_and_eval('\'tcmalloc::Static::central_cache_\'')
thread_heaps_ = gdb.parse_and_eval('\'tcmalloc::ThreadCache::thread_heaps_\'')
sizemap_ = gdb.parse_and_eval('\'tcmalloc::Static::sizemap_\'') # XXX cache
spantype = gdb.lookup_type('tcmalloc::Span').pointer()
knumclasses = gdb.parse_and_eval('kNumClasses') # XXX skip 0?
kmaxpages = gdb.parse_and_eval('kMaxPages')
pagesize = 1 << int(gdb.parse_and_eval('kPageShift'))
How can I compile Chromium, TCMalloc used by Chromium with debug symbols, those symbols?
Thanks,

Prevent double compilation of c files in cython

I am writing a wrapper over c libriary and this lib has file with almost all functions, let say, all_funcs.c. This file in turn requires compilation of lots of another c files
I have created all_funcs.pyx, where I wraped all functions, but I also want to create a submodule, that has access to functions from all_funcs.c. What works for now is adding all c-files to both Extensions in setup.py, however each c-file compiles twice: first for all_funcs.pyx and second for submodule extension.
Are there any ways to provide common sourse files to each Extension?
Example of current setup.py:
ext_helpers = Extension(name=SRC_DIR + '.wrapper.utils.helpers',
sources=[SRC_DIR + '/wrapper/utils/helpers.pyx'] + source_files_paths,
include_dirs=[SRC_DIR + '/include/'])
ext_all_funcs = Extension(name=SRC_DIR + '.wrapper.all_funcs',
sources=[SRC_DIR + '/wrapper/all_funcs.pyx'] + source_files_paths,
include_dirs=[SRC_DIR + '/include/'])
EXTENSIONS = [
ext_helpers,
ext_all_funcs,
]
if __name__ == "__main__":
setup(
packages=PACKAGES,
zip_safe=False,
name='some_name',
ext_modules=cythonize(EXTENSIONS, language_level=3)
)
source_files_paths - the list with common c source files
Note: this answer only explains how to avoid multiple compilation of c/cpp-files using libraries-argument of setup-function. It doesn't however explain how to avoid possible problems due to ODR-violation - for that see this SO-post.
Adding libraries-argument to setup will trigger build_clib prior to building of ext_modules (when running setup.py build or setup.py install commands), the resulting static library will also be automatically passed to the linker, when extensions are linked.
For your setup.py, this means:
from setuptools import setup, find_packages, Extension
...
#common c files compiled to a static library:
mylib = ('mylib', {'sources': source_files_paths}) # possible further settings
# no common c-files (taken care of in mylib):
ext_helpers = Extension(name=SRC_DIR + '.wrapper.utils.helpers',
sources=[SRC_DIR + '/wrapper/utils/helpers.pyx'],
include_dirs=[SRC_DIR + '/include/'])
# no common c-files (taken care of in mylib):
ext_all_funcs = Extension(name=SRC_DIR + '.wrapper.all_funcs',
sources=[SRC_DIR + '/wrapper/all_funcs.pyx'],
include_dirs=[SRC_DIR + '/include/'])
EXTENSIONS = [
ext_helpers,
ext_all_funcs,
]
if __name__ == "__main__":
setup(
packages=find_packages(where=SRC_DIR),
zip_safe=False,
name='some_name',
ext_modules=cythonize(EXTENSIONS, language_level=3),
# will be build as static libraries and automatically passed to linker:
libraries = [mylib]
)
To build the extensions inplace one should invoke:
python setupy.py build_clib build_ext --inplace
as build_ext alone is not enough: we need the static libraries to build before they can be used in extensions.

How do I find out what's buffering the communication from qemu to pexpect?

I have a Python2 program that runs qemu with a FreeBSD image.
expect()ing lines out output works.
However, expect()ing output that does not have its line terminated (such as when waiting for a prompt like login:) does not, this times out.
I suspect something in the communication between qemu and my program is doing line buffering, but how do I find out which of them it is? Candidates that I can think of:
FreeBSD itself. I find that unlikely, it shows prompts when running interactively, and qemu's -nographics options shouldn't make a difference for the emulated VM (but I may be wrong).
Something in the setup of the pty. I have zero experience with ptys. If that's the issue, this would be a bug in pexpect since pexpect is setting the pty up.
A bug in pexpect.
Something in my own script... but I have no clue what that could be.
For reference, here's the stripped-down code (including download and unpack, should anybody want to play with it):
#! /usr/bin/env python2
import os
import pexpect
import re
import sys
import time
def run(cmd):
'''Run command, log to stdout, no timeout, return the status code.'''
print('run: ' + cmd)
(output, rc) = pexpect.run(
cmd,
withexitstatus=1,
encoding='utf-8',
logfile=sys.stdout,
timeout=None
)
if rc != 0:
print('simple.py: Command failed with return code: ' + rc)
exit(rc)
download_path = 'https://download.freebsd.org/ftp/releases/VM-IMAGES/12.0-RELEASE/amd64/Latest'
image_file = 'FreeBSD-12.0-RELEASE-amd64.qcow2'
image_file_xz = image_file + '.xz'
if not os.path.isfile(image_file_xz):
run('curl -o %s %s/%s' % (image_file_xz, download_path, image_file_xz))
if not os.path.isfile(image_file):
# Reset image file to initial state
run('xz --decompress --keep --force --verbose ' + image_file_xz)
#cmd = 'qemu-system-x86_64 -snapshot -monitor none -display curses -chardev stdio,id=char0 ' + image_file
cmd = 'qemu-system-x86_64 -snapshot -nographic ' + image_file
print('interact with: ' + cmd)
child = pexpect.spawn(
cmd,
timeout=90, # FreeBSD takes roughly 60 seconds to boot
maxread=1,
)
child.logfile = sys.stdout
def expect(pattern):
result = child.expect([pexpect.TIMEOUT, pattern])
if result == 0:
print("timeout: %d reached when waiting for: %s" % (child.timeout, pattern))
exit(1)
return result - 1
if False:
# This does not work: the prompt is not visible, then timeout
expect('login: ')
else:
# Workaround, tested to work:
expect(re.escape('FreeBSD/amd64 (freebsd)')) # Line before prompt
time.sleep(1) # MUCH longer than actually needed, just to be safe
child.sendline('root')
# This will always time out, and terminate the script
expect('# ')
print('We want to get here but cannot')

How to make Chrome scale correctly in full screen mode in Xmonad

When I enter full screen mode with the F11 key, or click the full screen button in Youtube or Netflix, Chrome seems to scale the page to fit the size of the screen, and the page would be cropped to its containing window. However, after toggling the layout with mod + space, it then scales to fit the containing window correctly.
How do I make Chrome's scaling to fit its window instead of the entire screen when first entering full screen mode?
I tried the functions in XMonad.Hooks.EwmhDesktops and XMonad.Layout.Fullscreen but still couldn't figure out a way.
I'm using Google Chrome 57.0.2987.98 and xmonad 0.13 on Arch. Thanks!
My solution is to use this modified version of fullscreenEventHook from EWMH.
fullscreenEventHook :: Event -> Bool -> X All
fullscreenEventHook (ClientMessageEvent _ _ _ dpy win typ (action:dats)) isChrome = do
wmstate <- getAtom "_NET_WM_STATE"
fullsc <- getAtom "_NET_WM_STATE_FULLSCREEN"
wstate <- fromMaybe [] `fmap` getProp32 wmstate win
let isFull = fromIntegral fullsc `elem` wstate
-- Constants for the _NET_WM_STATE protocol:
remove = 0
add = 1
toggle = 2
ptype = 4 -- The atom property type for changeProperty
chWstate f = io $ changeProperty32 dpy win wmstate ptype propModeReplace (f wstate)
uglyChromeHack x = do
when (not isChrome) x
when isChrome $ windows W.swapUp >> windows W.swapDown
when (typ == wmstate && fi fullsc `elem` dats) $ do
when (action == add || (action == toggle && not isFull)) $ do
chWstate (fi fullsc:)
uglyChromeHack $ windows $ W.float win $ W.RationalRect 0 0 1 1
when (action == remove || (action == toggle && isFull)) $ do
chWstate $ delete (fi fullsc)
uglyChromeHack $ windows $ W.sink win
return $ All True
fullscreenEventHook _ _ = return $ All True
butNotChrome :: Event -> X All
butNotChrome e#(ClientMessageEvent _ _ _ _ win _ _) = do
isChrome <- runQuery (appName =? "google-chrome") win
fullscreenEventHook e isChrome
butNotChrome _ = return $ All True
This bit windows W.swapUp >> windows W.swapDown seems to kick chrome just hard enough.
This problem has bothered me for a while too. I tried all sorts of combinations in my xmonad config file but with no luck. But I've recently found 'Vivaldi', a browser based on the Chromium engine and headed by the ex-CEO of the Opera browser. It achieves exactly what you want by using the 'Toggle UI' option (by default, Ctrl-F11).
You need to add the following to your config (xmonad.hs):
import XMonad.Hooks.EwmhDesktops
main = xmonad $ ewmh (yourExistingConfigValueGoesHereExample { handleEventHook =
handleEventHook def <+> fullscreenEventHook })
More information can be found here: http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-EwmhDesktops.html
This functionality is also bundled into desktopConfig (a sort of sane default for xmonad). https://hackage.haskell.org/package/xmonad-contrib-0.13/docs/XMonad-Config-Desktop.html

How to read gzip-File with fopen in octave 3.2.4?

I need to open a gzip file with fopen. The manual (help fopen) explains to add b and z to the mode string:
[f, msg] = fopen('file.gz', 'rbz')
results to the error:
f = -1
msg =
rb and r work separately, but not with z. Do i misunderstand the manual?
An example file can be generated by
echo -e "1,2\n2,3\n3,4\n4,3\n5,5" | gzip > file.gz
The octave version 3.2.4 is caused by my operating system: Ubuntu 12.04.3 LTS
function data = zcatcsvfile(filename, firstline)
data = [];
[status, content] = system(cstrcat('zcat ', filename, ' | tail -n +', num2str(firstline)));
data = str2num(content);
endfunction
Use this function to read a gzipped file filename and read as first line firstline. If the file has a header of 5 lines:
data=zcatcsvfile('data.gz', 6)